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

Subversion Repositories usb1_funct

[/] [usb1_funct/] [trunk/] [bench/] [verilog/] [tests.v] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 rudi
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Test Case Collection                                       ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/cores/usb1_funct/////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
15
////                         www.asics.ws                        ////
16
////                         rudi@asics.ws                       ////
17
////                                                             ////
18
//// This source file may be used and distributed without        ////
19
//// restriction provided that this copyright statement is not   ////
20
//// removed from the file and that any derivative work contains ////
21
//// the original copyright notice and the associated disclaimer.////
22
////                                                             ////
23
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
24
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
25
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
26
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
27
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
28
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
29
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
30
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
31
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
32
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
33
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
34
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
35
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
36
////                                                             ////
37
/////////////////////////////////////////////////////////////////////
38
 
39
//  CVS Log
40
//
41
//  $Id: tests.v,v 1.1 2002-09-25 06:10:10 rudi Exp $
42
//
43
//  $Date: 2002-09-25 06:10:10 $
44
//  $Revision: 1.1 $
45
//  $Author: rudi $
46
//  $Locker:  $
47
//  $State: Exp $
48
//
49
// Change History:
50
//               $Log: not supported by cvs2svn $
51
//
52
//
53
//
54
//
55
//
56
//
57
 
58
 
59
task send_setup;
60
input   [7:0]    fa;
61
input   [7:0]    req_type;
62
input   [7:0]    request;
63
input   [15:0]   wValue;
64
input   [15:0]   wIndex;
65
input   [15:0]   wLength;
66
 
67
integer         len;
68
begin
69
 
70
buffer1[0] = req_type;
71
buffer1[1] = request;
72
buffer1[3] = wValue[15:8];
73
buffer1[2] = wValue[7:0];
74
buffer1[5] = wIndex[15:8];
75
buffer1[4] = wIndex[7:0];
76
buffer1[7] = wLength[15:8];
77
buffer1[6] = wLength[7:0];
78
 
79
buffer1_last = 0;
80
send_token(     fa,                     // Function Address
81
                0,                       // Logical Endpoint Number
82
                `USBF_T_PID_SETUP       // PID
83
                );
84
 
85
repeat(1)       @(posedge clk);
86
 
87
send_data(`USBF_T_PID_DATA0, 8, 1);
88
 
89
// Wait for ACK
90
utmi_recv_pack(len);
91
 
92
if(8'hd2 !== txmem[0])
93
   begin
94
        $display("ERROR: SETUP: ACK mismatch. Expected: %h, Got: %h (%t)",
95
        8'hd2, txmem[0], $time);
96
        error_cnt = error_cnt + 1;
97
   end
98
 
99
if(len !== 1)
100
   begin
101
        $display("ERROR: SETUP: Length mismatch. Expected: %h, Got: %h (%t)",
102
        8'h1, len, $time);
103
        error_cnt = error_cnt + 1;
104
   end
105
 
106
repeat(1)       @(posedge clk);
107
setup_pid = 1;
108
repeat(1)       @(posedge clk);
109
end
110
 
111
endtask
112
 
113
 
114
 
115
task data_in;
116
input   [7:0]    fa;
117
input   [7:0]    pl_size;
118
 
119
integer         rlen;
120
reg     [3:0]    pid, expect_pid;
121
begin
122
 
123
        buffer1_last = 0;
124
        repeat(5)       @(posedge clk);
125
        send_token(     fa,             // Function Address
126
                        0,               // Logical Endpoint Number
127
                        `USBF_T_PID_IN  // PID
128
                        );
129
 
130
        recv_packet(pid,rlen);
131
        if(setup_pid)   expect_pid = 4'hb; // DATA 1
132
        else            expect_pid = 4'h3; // DATA 0
133
 
134
        if(pid !== expect_pid)
135
           begin
136
                $display("ERROR: Data IN PID mismatch. Expected: %h, Got: %h (%t)",
137
                        expect_pid, pid, $time);
138
                error_cnt = error_cnt + 1;
139
           end
140
 
141
        setup_pid = ~setup_pid;
142
        if(rlen != pl_size)
143
           begin
144
                $display("ERROR: Data IN Size mismatch. Expected: %d, Got: %d (%t)",
145
                        pl_size, rlen, $time);
146
                error_cnt = error_cnt + 1;
147
           end
148
 
149
        for(n=0;n<rlen;n=n+1)
150
                $display("RCV Data[%0d]: %h",n,buffer1[n]);
151
 
152
        repeat(5)       @(posedge clk);
153
        send_token(     fa,             // Function Address
154
                        0,               // Logical Endpoint Number
155
                        `USBF_T_PID_ACK // PID
156
                        );
157
 
158
        repeat(5)       @(posedge clk);
159
 
160
end
161
endtask
162
 
163
 
164
 
165
task data_out;
166
input   [7:0]    fa;
167
input   [7:0]    pl_size;
168
 
169
integer len;
170
 
171
begin
172
        send_token(     fa,             // Function Address
173
                        0,               // Logical Endpoint Number
174
                        `USBF_T_PID_OUT // PID
175
                        );
176
 
177
        repeat(1)       @(posedge clk);
178
 
179
        if(setup_pid==0) send_data(`USBF_T_PID_DATA0, pl_size, 1);
180
        else                    send_data(`USBF_T_PID_DATA1, pl_size, 1);
181
 
182
        setup_pid = ~setup_pid;
183
 
184
        // Wait for ACK
185
        utmi_recv_pack(len);
186
 
187
        if(8'hd2 !== txmem[0])
188
           begin
189
                $display("ERROR: ACK mismatch. Expected: %h, Got: %h (%t)",
190
                8'hd2, txmem[0], $time);
191
                error_cnt = error_cnt + 1;
192
           end
193
 
194
        if(len !== 1)
195
           begin
196
                $display("ERROR: SETUP: Length mismatch. Expected: %h, Got: %h (%t)",
197
                8'h1, len, $time);
198
                error_cnt = error_cnt + 1;
199
           end
200
        repeat(5)       @(posedge clk);
201
 
202
end
203
endtask
204
 
205
 
206
parameter       GET_STATUS      =       8'h0,
207
                CLEAR_FEATURE   =       8'h1,
208
                SET_FEATURE     =       8'h3,
209
                SET_ADDRESS     =       8'h5,
210
                GET_DESCRIPTOR  =       8'h6,
211
                SET_DESCRIPTOR  =       8'h7,
212
                GET_CONFIG      =       8'h8,
213
                SET_CONFIG      =       8'h9,
214
                GET_INTERFACE   =       8'ha,
215
                SET_INTERFACE   =       8'hb,
216
                SYNCH_FRAME     =       8'hc;
217
 
218
 
219
task setup1;
220
 
221
begin
222
$display("\n\n");
223
$display("*****************************************************");
224
$display("*** CTRL ep test 1                                ***");
225
$display("*****************************************************\n");
226
 
227
 
228
$display("\n\nSetting Address ...");
229
 
230
send_setup(     8'h0,           // Function Address
231
                8'h00,          // Request Type
232
                SET_ADDRESS,    // Request
233
                16'h012,        // wValue
234
                16'h0,          // wIndex
235
                16'h0           // wLength
236
                );
237
 
238
// Status OK
239
data_in(        8'h0,           // Function Address
240
                8'h0            // Expected payload size
241
        );
242
 
243
 
244
$display("\n\nGetting descriptor ...");
245
send_setup(     8'h12,          // Function Address
246
                8'h80,          // Request Type
247
                GET_DESCRIPTOR, // Request
248
                16'h0100,       // wValue
249
                16'h0,          // wIndex
250
                16'h8           // wLength
251
                );
252
 
253
data_in(        8'h12,          // Function Address
254
                8'd08           // Expected payload size
255
        );
256
 
257
// Status OK
258
data_out(       8'h12,          // Function Address
259
                8'h0            // Expected payload size
260
        );
261
 
262
 
263
$display("\n\nGetting descriptor ...");
264
send_setup(     8'h12,          // Function Address
265
                8'h80,          // Request Type
266
                GET_DESCRIPTOR, // Request
267
                16'h0200,       // wValue
268
                16'h0,          // wIndex
269
                16'h8           // wLength
270
                );
271
 
272
data_in(        8'h12,          // Function Address
273
                8'd08           // Expected payload size
274
        );
275
 
276
// Status OK
277
data_out(       8'h12,          // Function Address
278
                8'h0            // Expected payload size
279
        );
280
 
281
$display("\n\nGetting descriptor ...");
282
send_setup(     8'h12,          // Function Address
283
                8'h80,          // Request Type
284
                GET_DESCRIPTOR, // Request
285
                16'h0200,       // wValue
286
                16'h0,          // wIndex
287
                16'd053         // wLength
288
                );
289
 
290
data_in(        8'h12,          // Function Address
291
                8'd053          // Expected payload size
292
        );
293
 
294
// Status OK
295
data_out(       8'h12,          // Function Address
296
                8'h0            // Expected payload size
297
        );
298
 
299
$display("\n\nGetting descriptor ...");
300
send_setup(     8'h12,          // Function Address
301
                8'h80,          // Request Type
302
                GET_DESCRIPTOR, // Request
303
                16'h0300,       // wValue
304
                16'h0,          // wIndex
305
                16'd04          // wLength
306
                );
307
 
308
data_in(        8'h12,          // Function Address
309
                8'd04           // Expected payload size
310
        );
311
 
312
// Status OK
313
data_out(       8'h12,          // Function Address
314
                8'h0            // Expected payload size
315
        );
316
 
317
$display("\n\nGetting descriptor ...");
318
send_setup(     8'h12,          // Function Address
319
                8'h80,          // Request Type
320
                GET_DESCRIPTOR, // Request
321
                16'h0301,       // wValue
322
                16'h0,          // wIndex
323
                16'd010         // wLength
324
                );
325
 
326
data_in(        8'h12,          // Function Address
327
                8'd010          // Expected payload size
328
        );
329
 
330
// Status OK
331
data_out(       8'h12,          // Function Address
332
                8'h0            // Expected payload size
333
        );
334
 
335
$display("\n\nGetting descriptor ...");
336
send_setup(     8'h12,          // Function Address
337
                8'h80,          // Request Type
338
                GET_DESCRIPTOR, // Request
339
                16'h0302,       // wValue
340
                16'h0,          // wIndex
341
                16'd08          // wLength
342
                );
343
 
344
data_in(        8'h12,          // Function Address
345
                8'd08           // Expected payload size
346
        );
347
 
348
// Status OK
349
data_out(       8'h12,          // Function Address
350
                8'h0            // Expected payload size
351
        );
352
 
353
$display("\n\nGetting descriptor ...");
354
send_setup(     8'h12,          // Function Address
355
                8'h80,          // Request Type
356
                GET_DESCRIPTOR, // Request
357
                16'h0303,       // wValue
358
                16'h0,          // wIndex
359
                16'd016         // wLength
360
                );
361
 
362
data_in(        8'h12,          // Function Address
363
                8'd010          // Expected payload size
364
        );
365
 
366
// Status OK
367
data_out(       8'h12,          // Function Address
368
                8'h0            // Expected payload size
369
        );
370
 
371
$display("\n\nGetting descriptor ...");
372
send_setup(     8'h12,          // Function Address
373
                8'h80,          // Request Type
374
                GET_DESCRIPTOR, // Request
375
                16'h0203,       // wValue
376
                16'h0,          // wIndex
377
                16'd053         // wLength
378
                );
379
 
380
data_in(        8'h12,          // Function Address
381
                8'd053          // Expected payload size
382
        );
383
 
384
// Status OK
385
data_out(       8'h12,          // Function Address
386
                8'h0            // Expected payload size
387
        );
388
 
389
show_errors;
390
$display("*****************************************************");
391
$display("*** Test DONE ...                                 ***");
392
$display("*****************************************************\n\n");
393
 
394
end
395
endtask
396
 
397
 
398
task in0;
399
 
400
reg     [6:0]    my_fa;
401
integer         quick, n, m, rlen,fc;
402
reg     [7:0]    fd;
403
integer         pack_cnt, pack_cnt_max;
404
reg     [7:0]    x;
405
reg     [3:0]    pid;
406
reg     [3:0]    expect_pid;
407
reg     [31:0]   data;
408
reg             pid_cnt;
409
 
410
begin
411
 
412
$display("\n\n");
413
$display("*****************************************************");
414
$display("*** IN ep test 0                                  ***");
415
$display("*****************************************************\n");
416
 
417
send_sof(11'h000 );     // Send SOF
418
 
419
pack_sz_max = 64;
420
pack_cnt_max = 4;
421
 
422
pid_cnt = 0;
423
my_fa = 7'h12;
424
 
425
for(pack_sz=0;pack_sz<pack_sz_max;pack_sz=pack_sz+1)
426
begin
427
 
428
$display("PL size: %0d", pack_sz);
429
 
430
for(pack_cnt=0;pack_cnt<pack_cnt_max;pack_cnt=pack_cnt+1)
431
   begin
432
 
433
        // Fill Buffer
434
        buffer1_last = 0;
435
        for(fc=0;fc<pack_sz;fc=fc+1)
436
           begin
437
                #2;
438
                while(ep1_f_full)       @(posedge clk);
439
 
440
                #1;
441
                //x = fc[7:0];
442
                x = $random;
443
                ep1_f_din = x;
444
                buffer0[fc] = x;
445
                ep1_f_we = 1;
446
                @(posedge clk);
447
                #1;
448
                ep1_f_we = 0;
449
                @(posedge clk);
450
           end
451
        #1;
452
        ep1_f_we = 0;
453
        @(posedge clk);
454
 
455
        // Send Data
456
        repeat(1)       @(posedge clk);
457
        send_sof(11'h000 );     // Send SOF
458
        repeat(1)       @(posedge clk);
459
        send_token(     my_fa,          // Function Address
460
                        1,              // Logical Endpoint Number
461
                        `USBF_T_PID_IN  // PID
462
                        );
463
 
464
        repeat(1)       @(posedge clk);
465
 
466
        recv_packet(pid,rlen);
467
 
468
        if(pid_cnt)     expect_pid = 4'hb;
469
        else            expect_pid = 4'h3;
470
        expect_pid = 4'h3;
471
 
472
        if(pid !== expect_pid)
473
           begin
474
                $display("ERROR: PID mismatch. Expected: %h, Got: %h (%t)",
475
                        expect_pid, pid, $time);
476
                error_cnt = error_cnt + 1;
477
           end
478
        pid_cnt = ~pid_cnt;
479
 
480
        if(rlen != pack_sz)
481
           begin
482
                $display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
483
                        pack_sz, rlen, $time);
484
                error_cnt = error_cnt + 1;
485
           end
486
 
487
        repeat(4)       @(posedge clk);
488
        send_token(     my_fa,          // Function Address
489
                        1,              // Logical Endpoint Number
490
                        `USBF_T_PID_ACK // PID
491
                        );
492
        repeat(5)       @(posedge clk);
493
 
494
        // Verify Data
495
        for(fc=0;fc<pack_sz;fc=fc+1)
496
           begin
497
                x =  buffer0[fc];
498
                if( (buffer1[fc] !== x) | ( (^buffer1[fc] ^ ^x) === 1'hx) )
499
                   begin
500
                        $display("ERROR: Data (%0d) mismatch. Expected: %h, Got: %h (%t)",
501
                        fc, buffer1[fc], x, $time);
502
                        error_cnt = error_cnt + 1;
503
                   end
504
           end
505
   end
506
 
507
repeat(50)      @(posedge clk);
508
end
509
 
510
show_errors;
511
$display("*****************************************************");
512
$display("*** Test DONE ...                                 ***");
513
$display("*****************************************************\n\n");
514
 
515
end
516
 
517
endtask
518
 
519
task out0;
520
reg     [6:0]    my_fa;
521
reg     [31:0]   data;
522
integer         len, n, no_pack, pl_sz;
523
integer         no_pack_max, pl_sz_max;
524
reg             pid;
525
 
526
reg     [7:0]    x;
527
 
528
begin
529
$display("\n\n");
530
$display("*****************************************************");
531
$display("*** OUT ep test 0                                 ***");
532
$display("*****************************************************\n");
533
 
534
 
535
no_pack_max = 4;        // Number Of packets to transfer
536
pl_sz_max   = 128;      // Payload Size
537
 
538
no_pack = 4;            // Number Of packets to transfer
539
pl_sz = 0;
540
my_fa = 7'h12;
541
 
542
 
543
for(pl_sz=0;pl_sz<pl_sz_max;pl_sz=pl_sz+4)
544
begin
545
pid = 0;
546
 
547
$display("PL size: %0d", pl_sz);
548
 
549
for(n=0;n<4096;n=n+1)
550
        //buffer1[n] = $random;
551
        buffer1[n] = n;
552
 
553
buffer1_last = 0;
554
 
555
fork
556
for(no_pack=0;no_pack<no_pack_max;no_pack=no_pack+1)     // Send no_pack Out packets
557
   begin
558
        repeat(1)       @(posedge clk);
559
        send_sof(11'h000 );     // Send SOF
560
        repeat(1)       @(posedge clk);
561
 
562
        send_token(     my_fa,          // Function Address
563
                        4,              // Logical Endpoint Number
564
                        `USBF_T_PID_OUT // PID
565
                        );
566
 
567
        repeat(1)       @(posedge clk);
568
 
569
        if(pid==0)       send_data(`USBF_T_PID_DATA0, pl_sz, 1);
570
        else            send_data(`USBF_T_PID_DATA1, pl_sz, 1);
571
 
572
        pid = ~pid;
573
 
574
        // Wait for ACK
575
        utmi_recv_pack(len);
576
 
577
        if(8'hd2 !== txmem[0])
578
           begin
579
                $display("ERROR: ACK mismatch. Expected: %h, Got: %h (%t)",
580
                8'hd2, txmem[0], $time);
581
                error_cnt = error_cnt + 1;
582
           end
583
 
584
        repeat(1)       @(posedge clk);
585
   end
586
 
587
   begin
588
        repeat(10)      @(posedge clk2);
589
        for(n=0;n<(no_pack_max*pl_sz);n=n+1)     // Compare Buffers
590
           begin
591
 
592
                #4;
593
                ep4_f_re = 0;
594
                repeat(1)       @(posedge clk2);
595
 
596
                while(ep4_f_empty)
597
                   begin
598
                        ep4_f_re = 0;
599
                        repeat(2)       @(posedge clk2);
600
                   end
601
 
602
                #2;
603
                if(buffer1[n] !== ep4_f_dout)
604
                   begin
605
                        $display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",
606
                                buffer1[n], ep4_f_dout, $time);
607
                        error_cnt = error_cnt + 1;
608
                   end
609
 
610
                ep4_f_re = 1;
611
                @(posedge clk2);
612
           end
613
        #1;
614
        ep4_f_re = 0;
615
        @(posedge clk2);
616
    end
617
 
618
join
619
 
620
repeat(1)       @(posedge clk);
621
end
622
 
623
show_errors;
624
$display("*****************************************************");
625
$display("*** Test DONE ...                                 ***");
626
$display("*****************************************************\n\n");
627
end
628
endtask
629
 
630
 

powered by: WebSVN 2.1.0

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