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

Subversion Repositories ha1588

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

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
    .rtc_timer_clk(rtc_timer_clk),
74 32 edn_walter
    .rtc_timer_in(rtc_timer_in),
75 5 ash_riple
 
76
    .q_rst(rst),
77
    .q_rd_clk(q_rd_clk),
78
    .q_rd_en(q_rd_en),
79
    .q_rd_stat(q_rd_stat),
80
    .q_rd_data(q_rd_data)
81 4 ash_riple
  );
82
 
83
gmii_rx_bfm BFM_RX
84
  (
85
    .gmii_rxclk(gmii_rxclk),
86
    .gmii_rxctrl(gmii_rxctrl),
87
    .gmii_rxdata(gmii_rxdata)
88
  );
89
 
90 13 edn_walter
 
91 15 edn_walter
tsu DUT_TX
92 4 ash_riple
  (
93
    .rst(rst),
94
 
95
    .gmii_clk(gmii_txclk),
96
    .gmii_ctrl(gmii_txctrl),
97
    .gmii_data(gmii_txdata),
98
 
99
    .rtc_timer_clk(rtc_timer_clk),
100 32 edn_walter
    .rtc_timer_in(rtc_timer_in),
101 5 ash_riple
 
102
    .q_rst(rst),
103
    .q_rd_clk(q_rd_clk),
104
    .q_rd_en(),
105
    .q_rd_stat(),
106
    .q_rd_data()
107 4 ash_riple
  );
108
 
109
gmii_tx_bfm BFM_TX
110
  (
111
    .gmii_txclk(gmii_txclk),
112
    .gmii_txctrl(gmii_txctrl),
113
    .gmii_txdata(gmii_txdata)
114
  );
115
 
116 36 edn_walter
integer rx_ptp_event_cnt, rx_ptp_mismatch_cnt;
117
integer ref_file_handle_rx, return_fscanf_rx, ref_num_rx;
118 35 edn_walter
initial begin
119 36 edn_walter
  rx_ptp_event_cnt = 0;
120
  rx_ptp_mismatch_cnt = 0;
121
  ref_file_handle_rx = $fopen("ptpdv2_rx.txt","r");
122 35 edn_walter
  forever @(posedge DUT_RX.q_wr_en) begin
123
    rx_ptp_event_cnt = rx_ptp_event_cnt + 1;
124 36 edn_walter
    return_fscanf_rx = $fscanf(ref_file_handle_rx, "%d", ref_num_rx);
125
    if (BFM_RX.num_rx != ref_num_rx) begin
126
      $warning("%d %d", BFM_RX.num_rx, ref_num_rx);
127
      rx_ptp_mismatch_cnt = rx_ptp_mismatch_cnt + 1;
128
    end
129 35 edn_walter
  end
130 36 edn_walter
  $fclose(ref_file_handle_rx);
131 35 edn_walter
end
132 13 edn_walter
 
133 36 edn_walter
integer tx_ptp_event_cnt, tx_ptp_mismatch_cnt;
134
integer ref_file_handle_tx, return_fscanf_tx, ref_num_tx;
135 35 edn_walter
initial begin
136 36 edn_walter
  tx_ptp_event_cnt = 0;
137
  tx_ptp_mismatch_cnt = 0;
138
  ref_file_handle_tx = $fopen("ptpdv2_tx.txt","r");
139 35 edn_walter
  forever @(posedge DUT_TX.q_wr_en) begin
140
    tx_ptp_event_cnt = tx_ptp_event_cnt + 1;
141 36 edn_walter
    return_fscanf_tx = $fscanf(ref_file_handle_tx, "%d", ref_num_tx);
142
    if (BFM_TX.num_tx != ref_num_tx) begin
143
      $warning("%d %d", BFM_TX.num_tx, ref_num_tx);
144
      tx_ptp_mismatch_cnt = tx_ptp_mismatch_cnt + 1;
145
    end
146 35 edn_walter
  end
147 36 edn_walter
  $fclose(ref_file_handle_tx);
148 35 edn_walter
end
149
 
150 36 edn_walter
initial begin
151
  fork
152
    @(posedge BFM_RX.eof_rx);
153
    @(posedge BFM_TX.eof_tx);
154
  join
155
 
156
  if (rx_ptp_event_cnt == 0)
157
    $display("RX Parser Test Fail: found 0 PTP-EVENT!");
158
 
159
  if (tx_ptp_event_cnt == 0)
160
    $display("TX Parser Test Fail: found 0 PTP-EVENT!");
161
 
162
  if      (rx_ptp_mismatch_cnt > 0)
163
    $display("Rx Parser Mismatch Found: RX-PTP-EVENT-MISMATCH = %d", rx_ptp_mismatch_cnt);
164
  else if (tx_ptp_mismatch_cnt > 0)
165
    $display("Tx Parser Mismatch Found: TX-PTP-EVENT-MISMATCH = %d", tx_ptp_mismatch_cnt);
166
  else
167
    $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);
168
 
169
  #100 $stop;
170
end
171
 
172 4 ash_riple
endmodule
173
 

powered by: WebSVN 2.1.0

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