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

Subversion Repositories firewire

[/] [firewire/] [trunk/] [bench/] [verilog/] [fw_link_tb.v] - Blame information for rev 11

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

Line No. Rev Author Line
1 11 johnsonw10
// $Id: fw_link_tb.v,v 1.1 2002-03-10 17:17:36 johnsonw10 Exp $
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// FIREWIRE IP Core                                             ////
5
////                                                              ////
6
//// This file is part of the firewire project                    ////
7
//// http://www.opencores.org/cores/firewire/                     ////
8
////                                                              ////
9
//// Description                                                  ////
10
//// Implementation of firewire IP core according to              ////
11
//// firewire IP core specification document.                     ////
12
////                                                              ////
13
//// To Do:                                                       ////
14
//// -                                                            ////
15
////                                                              ////
16
//// Author(s):                                                   ////
17
//// - johnsonw10@opencores.org                                   ////
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2001 Authors and OPENCORES.ORG                 ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE. See the GNU Lesser General Public License for more  ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
//
46
// CVS Revision History
47
//
48
// $Log: not supported by cvs2svn $
49
//
50
//
51
 
52
/**********************************************************************
53
  Design Notes:
54
  1. Startup sequence:
55
     * hard reset
56
     * set all enable signals
57
     * PHY receives self ID packet
58
     * PHY status receiving of self ID packet (PHYID write)
59
     *
60
     *
61
     *
62
***********************************************************************/
63
 
64
// synopsys translate_off
65
`include "timescale.v"
66
// synopsys translate_on
67
 
68
module fw_link_tb;
69
 
70
reg reset_n;
71
reg sclk;
72
 
73
wire [0:7] d;
74
wire [0:1] ctl;
75
 
76
wire [0:3] phy_reg_addr;
77
wire [0:7] phy_reg_data;
78
 
79
wire [0:31] grxf_data, atxf_data, itxf_data;
80
 
81
reg [0:31] selfid_data;
82
 
83
// host interface
84
reg [0:7]  host_addr;
85
wire [0:31] host_data;
86
reg  [0:31] host_data_out;  // driven by the host
87
 
88
reg        host_cs_n, host_wr_n;
89
reg [0:31] rcv_buf[0:63];
90
reg [0:31] send_buf[0:63];
91
 
92
reg [0:7]  phy_d;
93
reg [0:1]  phy_ctl;
94
reg        phy_oe;
95
 
96
reg [0:15] status_data;
97
 
98
integer grxf_data_num;
99
 
100
reg [0:31] atxf_din;
101
reg        atxf_wr;
102
 
103
reg [0:31] itxf_din;
104
reg        itxf_wr;
105
 
106
reg set_arb_won;
107
 
108
initial begin
109
    reset_n = 1;
110
    host_cs_n = 1;
111
    host_wr_n = 1;
112
 
113
    phy_oe = 0;
114
    phy_ctl = 2'b00;
115
    phy_d   = 8'h00;
116
    grxf_data_num = 0;
117
    atxf_wr = 0;
118
 
119
    #25 reset_n = 0;
120
    #100 reset_n = 1;
121
 
122
 
123
    // enable link_op (set bits 5, 6, 7, 8 @ 0x08)
124
    host_write_reg (16'h08, 32'h0780_0000);
125
 
126
    #100;
127
 
128
    // phy receive selfid packet #0
129
    selfid_data[0:1]   = 2'b01;          //selfid packet identifier
130
    selfid_data[2:7]   = 6'b00_0011;     //sender's phy_ID
131
    selfid_data[8]     = 1'b0;           //always 0
132
    selfid_data[9]     = 1'b1;           //link_active = 1
133
    selfid_data[10:15] = 6'b01_0000;     //gap_count = 10h
134
    selfid_data[16:17] = 2'b00;          //phy_speed = 100Mbit/s
135
    selfid_data[18:19] = 2'b00;          //phy_delay <= 144ns
136
    selfid_data[20]    = 1'b0;           //contender = 0
137
    selfid_data[21:23] = 3'b000;         //power_class = 0;
138
    selfid_data[24:25] = 2'b11;          //p0;
139
    selfid_data[26:27] = 2'b11;          //p1
140
    selfid_data[28:29] = 2'b11;          //p2
141
    selfid_data[30]    = 1'b0;           //initiated_reset = 0
142
    selfid_data[31]    = 1'b0;           //more_packets = 0
143
 
144
    rcv_buf[0] = selfid_data;
145
    rcv_buf[1] = ~selfid_data;
146
 
147
    $display ("PHY is in receive mode...");
148
    $display ("    data 0 = %h", rcv_buf[0]);
149
    $display ("    data 1 = %h", rcv_buf[1]);
150
    phy_rcv_pkt (2'b00, 2); //receive 2 32-bit word at 100Mbit/s
151
 
152
    #100;
153
 
154
    //phy status receviing self-id packet
155
    status_data[0]    = 1'b1;     // reset_gap = 1
156
    status_data[1]    = 1'b1;     // sub_gap = 1
157
    status_data[2]    = 1'b0;     // bus_reset = 0;
158
    status_data[3]    = 1'b0;     // bus_time_out = 0;
159
    status_data[4:7]  = 4'h0;     // physical_id addr
160
    status_data[8:15] = 8'b0010_1000;  // id = a, r = 0, ps = 0
161
 
162
    $display ("PHY is in status mode...");
163
    $display ("    status = %h", status_data);
164
    phy_status (status_data);
165
 
166
    // read request for data quadlet at 100Mbit/s
167
    // phy wins arbiration case
168
    set_arb_won = 1'b1;
169
 
170
    send_buf[0] = {16'h0000, 6'b010101, 2'b01, 4'h4, 4'h0};
171
    send_buf[1] = {16'haaaa, 16'h5555};
172
    send_buf[2] = 32'h1234_5678;
173
    $display ("LINK is sending read request for data for quadlet");
174
    $display ("    data 0 = %h", send_buf[0]);
175
    $display ("    data 1 = %h", send_buf[1]);
176
    $display ("    data 2 = %h", send_buf[2]);
177
 
178
    host_write_atxf (3);
179
 
180
end
181
 
182
initial sclk = 0;
183
always #10 sclk = ~sclk;   // 50MHz sclk
184
 
185
// atx FIFO
186
fifo_beh atxf (
187
               // Outputs
188
               .dout                    (atxf_data[0:31]),
189
               .empty                   (atxf_ef),
190
               .full                    (atxf_ff),
191
               // Inputs
192
               .reset_n                 (reset_n),
193
               .clk                     (sclk),
194
               .wr                      (atxf_wr),
195
               .din                     (atxf_din[0:31]),
196
               .rd                      (atxf_rd));
197
 
198
// itx FIFO
199
fifo_beh itxf (
200
               // Outputs
201
               .dout                    (itxf_data[0:31]),
202
               .empty                   (itxf_ef),
203
               .full                    (itxf_ff),
204
               // Inputs
205
               .reset_n                 (reset_n),
206
               .clk                     (sclk),
207
               .wr                      (itxf_wr),
208
               .din                     (itxf_din[0:31]),
209
               .rd                      (itxf_rd));
210
 
211
wire [0:15] src_id;
212
wire hard_rst = ~reset_n;
213
assign d = (phy_oe) ? phy_d : 8'hzz;
214
assign ctl = (phy_oe) ? phy_ctl : 2'bzz;
215
 
216
assign host_data = host_data_out;
217
 
218
fw_link_host_if link_host_if (/*AUTOINST*/
219
                              // Outputs
220
                              .src_id   (src_id[0:15]),
221
                              .tx_asy_en(tx_asy_en),
222
                              .rx_asy_en(rx_asy_en),
223
                              .tx_iso_en(tx_iso_en),
224
                              .rx_iso_en(rx_iso_en),
225
                              .soft_rst (soft_rst),
226
                              // Inouts
227
                              .host_data(host_data[0:31]),
228
                              // Inputs
229
                              .hard_rst (hard_rst),
230
                              .sclk     (sclk),
231
                              .host_cs_n(host_cs_n),
232
                              .host_wr_n(host_wr_n),
233
                              .host_addr(host_addr[0:7]));
234
 
235
fw_link_ctrl link_ctrl (/*AUTOINST*/
236
                        // Outputs
237
                        .lreq           (lreq),
238
                        .status_rcvd    (status_rcvd),
239
                        .arb_reset_gap  (arb_reset_gap),
240
                        .sub_gap        (sub_gap),
241
                        .bus_reset      (bus_reset),
242
                        .state_time_out (state_time_out),
243
                        .phy_reg_addr   (phy_reg_addr[0:3]),
244
                        .phy_reg_data   (phy_reg_data[0:7]),
245
                        .atxf_rd        (atxf_rd),
246
                        .itxf_rd        (itxf_rd),
247
                        .grxf_we        (grxf_we),
248
                        .grxf_data      (grxf_data[0:31]),
249
                        // Inouts
250
                        .d              (d[0:7]),
251
                        .ctl            (ctl[0:1]),
252
                        // Inputs
253
                        .hard_rst       (hard_rst),
254
                        .sclk           (sclk),
255
                        .src_id         (src_id[0:15]),
256
                        .soft_rst       (soft_rst),
257
                        .tx_asy_en      (tx_asy_en),
258
                        .rx_asy_en      (rx_asy_en),
259
                        .tx_iso_en      (tx_iso_en),
260
                        .rx_iso_en      (rx_iso_en),
261
                        .atxf_ef        (atxf_ef),
262
                        .atxf_data      (atxf_data[0:31]),
263
                        .itxf_ef        (itxf_ef),
264
                        .itxf_data      (itxf_data[0:31]),
265
                        .grxf_ff        (grxf_ff));
266
 
267
 
268
// simple phy arbitor model
269
// ctl pin encodings
270
parameter CTL_IDLE     = 2'b00;
271
// encodings when PHY has control
272
parameter CTL_PHY_STATUS   = 2'b01;
273
parameter CTL_PHY_RECEIVE  = 2'b10;
274
parameter CTL_PHY_TRANSMIT = 2'b11;
275
// encodings when link has control
276
parameter CTL_LINK_HOLD     = 2'b01;
277
parameter CTL_LINK_TRANSMIT = 2'b10;
278
parameter CTL_LINK_UNUSED   = 2'b11;
279
 
280
wire lreq_sent;
281
 
282
assign lreq_sent = link_ctrl.link_req.req_sent;
283
 
284
always begin
285
    wait (lreq_sent);
286
    repeat (10) @ (posedge sclk); // wait for 10 clock cycles
287
 
288
    if (set_arb_won) begin
289
        // send arb won sequence on ctl pin
290
        @ (posedge sclk);
291
        phy_oe = 1'b1;
292
        phy_ctl = CTL_PHY_TRANSMIT;
293
        @ (posedge sclk);
294
        phy_ctl = CTL_IDLE;
295
        // release control of ctl and d
296
        @ (posedge sclk);
297
        phy_oe = 1'b0;
298
    end
299
    else begin
300
        // send arb lose sequence on ctl pin
301
        @ (posedge sclk);
302
        phy_oe = 1'b1;
303
        phy_ctl = CTL_PHY_RECEIVE;
304
        @ (posedge sclk);
305
        phy_ctl = CTL_IDLE;
306
    end
307
end
308
 
309
 
310
 
311
// grxf monitor
312
always @ (posedge sclk) begin : grxf_monitor
313
    if (grxf_we) begin
314
        $display ("===>Writing GRXF data[%d] = %h", grxf_data_num, grxf_data);
315
        grxf_data_num <= grxf_data_num + 1;
316
    end
317
end
318
 
319
// status monitor
320
always @ (posedge sclk) begin : status_monitor
321
    if (status_rcvd) begin
322
        $display ("===>Received status = %h", {arb_reset_gap, sub_gap,
323
                                           bus_reset, state_time_out,
324
                                           phy_reg_addr, phy_reg_data});
325
        $display ("    arb_reset_gap = %h", arb_reset_gap);
326
        $display ("    sub_gap = %h", sub_gap);
327
        $display ("    bus_reset = %h", bus_reset);
328
        $display ("    state_time_out = %h", state_time_out);
329
        $display ("    phy_reg_addr = %h", phy_reg_addr);
330
        $display ("    phy_reg_data = %h", phy_reg_data);
331
    end
332
end
333
 
334
`include "fw_phy_tasks.v"
335
`include "fw_host_tasks.v"
336
 
337
endmodule // fw_link_tb
338
 
339
// Local Variables:
340
// verilog-library-directories:("." "../../rtl/verilog")
341
// End:

powered by: WebSVN 2.1.0

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