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

Subversion Repositories usb11

[/] [usb11/] [trunk/] [bench/] [verilog/] [test_bench_ocp_top.v] - Blame information for rev 15

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

Line No. Rev Author Line
1 2 alfoltran
////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  USB 1.1 Top Level Test Bench - OCP Interface               ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////  Modifications: Alfredo Luiz Foltran Fialho                 ////
10
////                 alfoltran@opencores.org                     ////
11
////                                                             ////
12
////  Downloaded from: http://www.opencores.org/cores/usb1_funct/////
13
////                                                             ////
14
/////////////////////////////////////////////////////////////////////
15
////                                                             ////
16
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
17
////                         www.asics.ws                        ////
18
////                         rudi@asics.ws                       ////
19
////                                                             ////
20
//// This source file may be used and distributed without        ////
21
//// restriction provided that this copyright statement is not   ////
22
//// removed from the file and that any derivative work contains ////
23
//// the original copyright notice and the associated disclaimer.////
24
////                                                             ////
25
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
26
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
27
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
28
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
29
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
30
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
31
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
32
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
33
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
34
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
35
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
36
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
37
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
38
////                                                             ////
39
/////////////////////////////////////////////////////////////////////
40
 
41
`include "timescale.v"
42
`include "usb_defines.v"
43
`include "usb_ocp.v"
44
 
45
module test;
46
 
47
///////////////////////////////////////////////////////////////////
48
//
49
// Local IOs and Vars
50
//
51
 
52
reg             clk;
53
reg             clk2;
54
reg             rst;
55
 
56
integer         error_cnt;
57
reg     [7:0]    txmem[0:2048];
58
reg     [7:0]    buffer1[0:16384];
59
reg     [7:0]    buffer0[0:16384];
60
integer         buffer1_last;
61
reg     [31:0]   wd_cnt;
62
reg             setup_pid;
63
integer         pack_sz, pack_sz_max;
64
wire            tx_dp, tx_dn, tx_oe;
65
wire            rx_d, rx_dp, rx_dn;
66
reg             tb_tx_valid;
67
wire            tb_tx_ready;
68
reg     [7:0]    tb_txdata;
69
wire            tb_rx_valid, tb_rx_active, tb_rx_error;
70
wire    [7:0]    tb_rxdata;
71
 
72
reg     [7:0]    ep_f_din;
73
wire    [7:0]    ep_f_dout;
74
reg     [2:0]    cmd;
75
 
76
reg     [31:0]   ep_f_addr;
77
 
78
reg     [7:0]    ep0_max_size;
79
reg     [7:0]    ep1_max_size;
80
reg     [7:0]    ep2_max_size;
81
reg     [7:0]    ep3_max_size;
82
reg     [7:0]    ep4_max_size;
83
reg     [7:0]    ep5_max_size;
84
reg     [7:0]    ep6_max_size;
85
reg     [7:0]    ep7_max_size;
86
 
87
wire    [7:0]    flags;
88
 
89
wire            rx_dp1;
90
wire            rx_dn1;
91
wire            tx_dp1;
92
wire            tx_dn1;
93
wire            rx_dp2;
94
wire            rx_dn2;
95
wire            tx_dp2;
96
wire            tx_dn2;
97
 
98
reg             usb_reset;
99
integer         n;
100
reg     [31:0]   data;
101
 
102
///////////////////////////////////////////////////////////////////
103
//
104
// Test Definitions
105
//
106
 
107
///////////////////////////////////////////////////////////////////
108
//
109
// Initial Startup and Simulation Begin
110
//
111
 
112
 
113
initial
114
   begin
115
        usb_reset = 0;
116
        $timeformat (-9, 1, " ns", 12);
117
 
118
`ifdef WAVES
119
        $shm_open("waves");
120
        $shm_probe("AS",test,"AS");
121
        $display("INFO: Signal dump enabled ...\n\n");
122
`endif
123
        tb_tx_valid = 0;
124
        error_cnt = 0;
125
        wd_cnt = 0;
126
        clk = 0;
127
        clk2 = 0;
128
        rst = 0;
129
        cmd=3'b100;
130
        ep_f_addr=32'h00;
131
 
132
        repeat(10)      @(posedge clk);
133
        rst = 1;
134
        repeat(50)      @(posedge clk);
135
        usb_reset = 1;
136
        repeat(300)     @(posedge clk);
137
        usb_reset = 0;
138
        repeat(10)      @(posedge clk);
139
 
140
        if(1)
141
           begin
142
                setup0;
143
                in1;
144
                out2;
145
                in3;
146
                out4;
147
                in5;
148
                out6;
149
           end
150
        else
151
        if(1)
152
           begin
153
                setup0;
154
           end
155
 
156
        repeat(500)     @(posedge clk);
157
        $finish;
158
   end
159
 
160
///////////////////////////////////////////////////////////////////
161
//
162
// Watchdog Timer
163
//
164
always @(posedge clk)
165
        if(tx_dp1 | tx_dp2)             wd_cnt <= #1 0;
166
        else                            wd_cnt <= #1 wd_cnt + 1;
167
 
168
always @(wd_cnt)
169
        if(wd_cnt>5000)
170
           begin
171
                $display("\n\n*************************************\n");
172
                $display("ERROR: Watch Dog Counter Expired\n");
173
                $display("*************************************\n\n\n");
174
                $finish;
175
           end
176
 
177
///////////////////////////////////////////////////////////////////
178
//
179
// Clock generation
180
//
181
 
182
always #10.42 clk = ~clk;
183
always #10.42 clk2 = ~clk2;
184
 
185
///////////////////////////////////////////////////////////////////
186
//
187
// Module Instantiations
188
//
189
 
190
usb_phy tb_phy(.clk(                    clk                     ),
191
                .rst(                   rst                     ),
192
 
193
                .phy_tx_mode(           1'b1                    ),
194
                .usb_rst(                                       ),
195
 
196
                .rxd(                   rx_dp1                  ),
197
                .rxdp(                  rx_dp1                  ),
198
                .rxdn(                  rx_dn1                  ),
199
 
200
                .txdp(                  tx_dp1                  ),
201
                .txdn(                  tx_dn1                  ),
202
                .txoe(                                          ),
203
 
204
                .DataIn_o(              tb_rxdata               ),
205
                .RxValid_o(             tb_rx_valid             ),
206
                .RxActive_o(            tb_rx_active            ),
207
                .RxError_o(             tb_rx_error             ),
208
 
209
                .DataOut_i(             tb_txdata               ),
210
                .TxValid_i(             tb_tx_valid             ),
211
                .TxReady_o(             tb_tx_ready             ),
212
                .LineState_o(                                   )
213
                );
214
 
215
parameter       LD = 40;
216
 
217
assign #(LD) rx_dp1 = !usb_reset & tx_dp2;
218
assign #(LD) rx_dn1 = !usb_reset & tx_dn2;
219
 
220
assign #(LD) rx_dp2 = !usb_reset & tx_dp1;
221
assign #(LD) rx_dn2 = !usb_reset & tx_dn1;
222
 
223
usb_ocp u0(     .Clk(                   clk2                    ),
224
                .Reset_n(                       rst                     ),
225
 
226
                // USB Status
227
                .SFlag( flags),
228
                .SError(                                        ),
229
 
230
                // Interrupts
231
                .SInterrupt(                                    ),
232
 
233
                // USB PHY Interface
234
                .tx_dp(                 tx_dp2                  ),
235
                .tx_dn(                 tx_dn2                  ),
236
                .tx_oe(                                         ),
237
                .rx_d(                  rx_dp2                  ),
238
                .rx_dp(                 rx_dp2                  ),
239
                .rx_dn(                 rx_dn2                  ),
240
 
241
                // OCP Interface
242
                .MData(                 ep_f_din                ),
243
                .SData(                 ep_f_dout               ),
244
                .MCmd(          cmd             ),
245
                .MAddr(                 ep_f_addr               )
246
                );
247
 
248
///////////////////////////////////////////////////////////////////
249
//
250
// Test and test lib Includes
251
//
252
`include "tests_lib.v"
253
`include "tests_ocp.v"
254
 
255
endmodule
256
 

powered by: WebSVN 2.1.0

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