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

Subversion Repositories usb11

[/] [usb11/] [trunk/] [bench/] [verilog/] [tests_ocp.v] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfoltran
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Test Case Collection                                       ////
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
//  CVS Log
42
//
43 11 alfoltran
//  $Id: tests_ocp.v,v 1.3 2004-05-28 23:13:16 alfoltran Exp $
44 2 alfoltran
//
45 11 alfoltran
//  $Date: 2004-05-28 23:13:16 $
46
//  $Revision: 1.3 $
47 2 alfoltran
//  $Author: alfoltran $
48
//  $Locker:  $
49
//  $State: Exp $
50
//
51
// Change History:
52
//               $Log: not supported by cvs2svn $
53 11 alfoltran
//               Revision 1.2  2004/05/11 18:51:08  alfoltran
54
//               Task in5 correction: no ACK for length zero packet.
55
//
56 6 alfoltran
//               Revision 1.1  2004/05/10 19:23:26  alfoltran
57
//               Initial version in OpenCores.org (2004/04/10 - 19:22GMT)
58
//
59 2 alfoltran
//               Revision 1.1  2002/09/25 06:10:10  rudi
60
//               Added Test Bench
61
//
62
//
63
//
64
//
65
//
66
//
67
//
68
 
69
 
70
task send_setup;
71
input   [7:0]    fa;
72
input   [7:0]    req_type;
73
input   [7:0]    request;
74
input   [15:0]   wValue;
75
input   [15:0]   wIndex;
76
input   [15:0]   wLength;
77
 
78
integer         len;
79
begin
80
 
81
buffer1[0] = req_type;
82
buffer1[1] = request;
83
buffer1[3] = wValue[15:8];
84
buffer1[2] = wValue[7:0];
85
buffer1[5] = wIndex[15:8];
86
buffer1[4] = wIndex[7:0];
87
buffer1[7] = wLength[15:8];
88
buffer1[6] = wLength[7:0];
89
 
90
buffer1_last = 0;
91
send_token(     fa,                     // Function Address
92
                0,                       // Logical Endpoint Number
93
                `USBF_T_PID_SETUP       // PID
94
                );
95
 
96
repeat(1)       @(posedge clk);
97
 
98
send_data(`USBF_T_PID_DATA0, 8, 1);
99
 
100
// Wait for ACK
101
utmi_recv_pack(len);
102
 
103
if(8'hd2 !== txmem[0])
104
   begin
105
        $display("ERROR: SETUP: ACK mismatch. Expected: %h, Got: %h (%t)",
106
        8'hd2, txmem[0], $time);
107
        error_cnt = error_cnt + 1;
108
   end
109
 
110
if(len !== 1)
111
   begin
112
        $display("ERROR: SETUP: Length mismatch. Expected: %h, Got: %h (%t)",
113
        8'h1, len, $time);
114
        error_cnt = error_cnt + 1;
115
   end
116
 
117
repeat(1)       @(posedge clk);
118
setup_pid = 1;
119
repeat(1)       @(posedge clk);
120
end
121
 
122
endtask
123
 
124
 
125
 
126
task data_in;
127
input   [7:0]    fa;
128
input   [7:0]    pl_size;
129
 
130
integer         rlen;
131
reg     [3:0]    pid, expect_pid;
132
begin
133
 
134
        buffer1_last = 0;
135
        repeat(5)       @(posedge clk);
136
        send_token(     fa,             // Function Address
137
                        0,               // Logical Endpoint Number
138
                        `USBF_T_PID_IN  // PID
139
                        );
140
 
141
        recv_packet(pid,rlen);
142
        if(setup_pid)   expect_pid = 4'hb; // DATA 1
143
        else            expect_pid = 4'h3; // DATA 0
144
 
145
        if(pid !== expect_pid)
146
           begin
147
                $display("ERROR: Data IN PID mismatch. Expected: %h, Got: %h (%t)",
148
                        expect_pid, pid, $time);
149
                error_cnt = error_cnt + 1;
150
           end
151
 
152
        setup_pid = ~setup_pid;
153
        if(rlen != pl_size)
154
           begin
155
                $display("ERROR: Data IN Size mismatch. Expected: %d, Got: %d (%t)",
156
                        pl_size, rlen, $time);
157
                error_cnt = error_cnt + 1;
158
           end
159
 
160
        for(n=0;n<rlen;n=n+1)
161
                $display("RCV Data[%0d]: %h",n,buffer1[n]);
162
 
163
        repeat(5)       @(posedge clk);
164
        send_token(     fa,             // Function Address
165
                        0,               // Logical Endpoint Number
166
                        `USBF_T_PID_ACK // PID
167
                        );
168
 
169
        repeat(5)       @(posedge clk);
170
 
171
end
172
endtask
173
 
174
 
175
 
176
task data_out;
177
input   [7:0]    fa;
178
input   [7:0]    pl_size;
179
 
180
integer len;
181
 
182
begin
183
        send_token(     fa,             // Function Address
184
                        0,               // Logical Endpoint Number
185
                        `USBF_T_PID_OUT // PID
186
                        );
187
 
188
        repeat(1)       @(posedge clk);
189
 
190
        if(setup_pid==0) send_data(`USBF_T_PID_DATA0, pl_size, 1);
191
        else                    send_data(`USBF_T_PID_DATA1, pl_size, 1);
192
 
193
        setup_pid = ~setup_pid;
194
 
195
        // Wait for ACK
196
        utmi_recv_pack(len);
197
 
198
        if(8'hd2 !== txmem[0])
199
           begin
200
                $display("ERROR: ACK mismatch. Expected: %h, Got: %h (%t)",
201
                8'hd2, txmem[0], $time);
202
                error_cnt = error_cnt + 1;
203
           end
204
 
205
        if(len !== 1)
206
           begin
207
                $display("ERROR: SETUP: Length mismatch. Expected: %h, Got: %h (%t)",
208
                8'h1, len, $time);
209
                error_cnt = error_cnt + 1;
210
           end
211
        repeat(5)       @(posedge clk);
212
 
213
end
214
endtask
215
 
216
 
217
parameter       GET_STATUS      =       8'h0,
218
                CLEAR_FEATURE   =       8'h1,
219
                SET_FEATURE     =       8'h3,
220
                SET_ADDRESS     =       8'h5,
221
                GET_DESCRIPTOR  =       8'h6,
222
                SET_DESCRIPTOR  =       8'h7,
223
                GET_CONFIG      =       8'h8,
224
                SET_CONFIG      =       8'h9,
225
                GET_INTERFACE   =       8'ha,
226
                SET_INTERFACE   =       8'hb,
227
                SYNCH_FRAME     =       8'hc;
228
 
229
 
230
task setup0;
231
 
232
begin
233
$display("\n\n");
234
$display("*****************************************************");
235
$display("*** CTRL ep test 0                                ***");
236
$display("*****************************************************\n");
237
 
238
 
239
$display("\n\nSetting Address ...");
240
 
241
send_setup(     8'h0,           // Function Address
242
                8'h00,          // Request Type
243
                SET_ADDRESS,    // Request
244
                16'h012,        // wValue
245
                16'h0,          // wIndex
246
                16'h0           // wLength
247
                );
248
 
249
// Status OK
250
data_in(        8'h0,           // Function Address
251
                8'h0            // Expected payload size
252
        );
253
 
254
$display("\n\nGetting descriptor ...");
255
send_setup(     8'h12,          // Function Address
256
                8'h80,          // Request Type
257
                GET_DESCRIPTOR, // Request
258
                16'h0100,       // wValue
259
                16'h0,          // wIndex
260
                16'h12          // wLength
261
                );
262
 
263
data_in(        8'h12,          // Function Address
264
                8'd18           // Expected payload size
265
        );
266
 
267
// Status OK
268
data_out(       8'h12,          // Function Address
269
                8'h0            // Expected payload size
270
        );
271
 
272
$display("\n\nGetting descriptor ...");
273
send_setup(     8'h12,          // Function Address
274
                8'h80,          // Request Type
275
                GET_DESCRIPTOR, // Request
276
                16'h0200,       // wValue
277
                16'h0,          // wIndex
278
                16'h9           // wLength
279
                );
280
 
281
data_in(        8'h12,          // Function Address
282
                8'd9            // Expected payload size
283
        );
284
 
285
// Status OK
286
data_out(       8'h12,          // Function Address
287
                8'h0            // Expected payload size
288
        );
289
 
290
$display("\n\nGetting descriptor ...");
291
send_setup(     8'h12,          // Function Address
292
                8'h80,          // Request Type
293
                GET_DESCRIPTOR, // Request
294
                16'h0200,       // wValue
295
                16'h0,          // wIndex
296
                16'd060         // wLength
297
                );
298
 
299
data_in(        8'h12,          // Function Address
300
                8'd060          // Expected payload size
301
        );
302
 
303
// Status OK
304
data_out(       8'h12,          // Function Address
305
                8'h0            // Expected payload size
306
        );
307
 
308
$display("\n\nGetting descriptor ...");
309
send_setup(     8'h12,          // Function Address
310
                8'h80,          // Request Type
311
                GET_DESCRIPTOR, // Request
312
                16'h0300,       // wValue
313
                16'h0,          // wIndex
314
                16'd08          // wLength
315
                );
316
 
317
data_in(        8'h12,          // Function Address
318
                8'd08           // Expected payload size
319
        );
320
 
321
// Status OK
322
data_out(       8'h12,          // Function Address
323
                8'h0            // Expected payload size
324
        );
325
 
326
$display("\n\nGetting descriptor ...");
327
send_setup(     8'h12,          // Function Address
328
                8'h80,          // Request Type
329
                GET_DESCRIPTOR, // Request
330
                16'h0301,       // wValue
331
                16'h0416,       // wIndex
332
                16'd026         // wLength
333
                );
334
 
335
data_in(        8'h12,          // Function Address
336
                8'd026          // Expected payload size
337
        );
338
 
339
// Status OK
340
data_out(       8'h12,          // Function Address
341
                8'h0            // Expected payload size
342
        );
343
 
344
$display("\n\nGetting descriptor ...");
345
send_setup(     8'h12,          // Function Address
346
                8'h80,          // Request Type
347
                GET_DESCRIPTOR, // Request
348
                16'h0302,       // wValue
349
                16'h0416,       // wIndex
350
                16'd028         // wLength
351
                );
352
 
353
data_in(        8'h12,          // Function Address
354
                8'd028          // Expected payload size
355
        );
356
 
357
// Status OK
358
data_out(       8'h12,          // Function Address
359
                8'h0            // Expected payload size
360
        );
361
 
362
$display("\n\nGetting descriptor ...");
363
send_setup(     8'h12,          // Function Address
364
                8'h80,          // Request Type
365
                GET_DESCRIPTOR, // Request
366
                16'h0303,       // wValue
367
                16'h0416,       // wIndex
368
                16'd054         // wLength
369
                );
370
 
371
data_in(        8'h12,          // Function Address
372
                8'd054          // Expected payload size
373
        );
374
 
375
// Status OK
376
data_out(       8'h12,          // Function Address
377
                8'h0            // Expected payload size
378
        );
379
 
380
show_errors;
381
$display("*****************************************************");
382
$display("*** Test DONE ...                                 ***");
383
$display("*****************************************************\n\n");
384
 
385
end
386
endtask
387
 
388
task in1;
389
 
390
reg     [6:0]    my_fa;
391
integer         quick, n, m, rlen,fc;
392
reg     [7:0]    fd;
393
integer         pack_cnt, pack_cnt_max;
394
reg     [7:0]    x;
395
reg     [3:0]    pid;
396
reg     [3:0]    expect_pid;
397
reg     [31:0]   data;
398
reg             pid_cnt;
399
 
400
begin
401
 
402
$display("\n\n");
403
$display("*****************************************************");
404
$display("*** IN ep test 1                                  ***");
405
$display("*****************************************************\n");
406
 
407
send_sof(11'h000 );     // Send SOF
408
 
409
pack_sz_max = 256;
410
pack_cnt_max = 4;
411
 
412
pid_cnt = 0;
413
my_fa = 7'h12;
414
 
415
ep_f_addr=32'h01;
416
cmd=3'b000;
417
 
418
for(pack_sz=0;pack_sz<=pack_sz_max;pack_sz=pack_sz+32)
419
begin
420
 
421
$display("PL size: %0d", pack_sz);
422
 
423
for(pack_cnt=0;pack_cnt<pack_cnt_max;pack_cnt=pack_cnt+1)
424
   begin
425
 
426
        // Fill Buffer
427
        buffer1_last = 0;
428
        for(fc=0;fc<pack_sz;fc=fc+1)
429
           begin
430
                #2;
431
                while(flags[1]) @(posedge clk);
432
 
433
                #1;
434
                //x = fc[7:0];
435
                x = $random;
436
                ep_f_din = x;
437
                buffer0[fc] = x;
438
                cmd = 3'b001;
439
                @(posedge clk);
440
                #1;
441
                cmd = 3'b000;
442
                @(posedge clk);
443
           end
444
        #1;
445
        cmd = 3'b000;
446
        @(posedge clk);
447
 
448
        // Send Data
449
        repeat(1)       @(posedge clk);
450
        send_sof(11'h000 );     // Send SOF
451
        repeat(1)       @(posedge clk);
452
        send_token(     my_fa,          // Function Address
453
                        1,              // Logical Endpoint Number
454
                        `USBF_T_PID_IN  // PID
455
                        );
456
 
457
        repeat(1)       @(posedge clk);
458
 
459
        recv_packet(pid,rlen);
460
 
461
        if(pid_cnt)     expect_pid = 4'hb;
462
        else            expect_pid = 4'h3;
463
        expect_pid = 4'h3;
464
 
465
        if(pid !== expect_pid)
466
           begin
467
                $display("ERROR: PID mismatch. Expected: %h, Got: %h (%t)",
468
                        expect_pid, pid, $time);
469
                error_cnt = error_cnt + 1;
470
           end
471
        pid_cnt = ~pid_cnt;
472
 
473
        if(rlen != pack_sz)
474
           begin
475
                $display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
476
                        pack_sz, rlen, $time);
477
                error_cnt = error_cnt + 1;
478
           end
479
 
480
        repeat(4)       @(posedge clk);
481
 
482
        // Verify Data
483
        for(fc=0;fc<pack_sz;fc=fc+1)
484
           begin
485
                x =  buffer0[fc];
486
                if( (buffer1[fc] !== x) | ( (^buffer1[fc] ^ ^x) === 1'hx) )
487
                   begin
488
                        $display("ERROR: Data (%0d) mismatch. Expected: %h, Got: %h (%t)",
489
                                fc, x, buffer1[fc], $time);
490
                        error_cnt = error_cnt + 1;
491
                   end
492
           end
493
   end
494
 
495
repeat(50)      @(posedge clk);
496
end
497
 
498
cmd = 100;
499
ep_f_addr=32'h0;
500
 
501
show_errors;
502
$display("*****************************************************");
503
$display("*** Test DONE ...                                 ***");
504
$display("*****************************************************\n\n");
505
 
506
end
507
 
508
endtask
509
 
510
task out2;
511
reg     [6:0]    my_fa;
512
reg     [31:0]   data;
513
integer         len, n, no_pack, pl_sz;
514
integer         no_pack_max, pl_sz_max;
515
reg             pid;
516
 
517
reg     [7:0]    x;
518
 
519
begin
520
$display("\n\n");
521
$display("*****************************************************");
522
$display("*** OUT ep test 2                                 ***");
523
$display("*****************************************************\n");
524
 
525
 
526
no_pack_max = 4;        // Number Of packets to transfer
527
pl_sz_max   = 256;      // Payload Size
528
 
529
no_pack = 4;            // Number Of packets to transfer
530
pl_sz = 0;
531
my_fa = 7'h12;
532
 
533
ep_f_addr=32'h02;
534
cmd=3'b000;
535
 
536
for(pl_sz=0;pl_sz<=pl_sz_max;pl_sz=pl_sz+32)
537
begin
538
pid = 0;
539
 
540
$display("PL size: %0d", pl_sz);
541
 
542
for(n=0;n<4096;n=n+1)
543
        //buffer1[n] = $random;
544
        buffer1[n] = n;
545
 
546
buffer1_last = 0;
547
 
548
fork
549
for(no_pack=0;no_pack<no_pack_max;no_pack=no_pack+1)     // Send no_pack Out packets
550
   begin
551
        repeat(1)       @(posedge clk);
552
        send_sof(11'h000 );     // Send SOF
553
        repeat(1)       @(posedge clk);
554
 
555
        send_token(     my_fa,          // Function Address
556
                        2,              // Logical Endpoint Number
557
                        `USBF_T_PID_OUT // PID
558
                        );
559
 
560
        repeat(1)       @(posedge clk);
561
 
562
        if(pid==0)       send_data(`USBF_T_PID_DATA0, pl_sz, 1);
563
        else            send_data(`USBF_T_PID_DATA1, pl_sz, 1);
564
   end
565
 
566
   begin
567
        repeat(10)      @(posedge clk2);
568
        for(n=0;n<(no_pack_max*pl_sz);n=n+1)     // Compare Buffers
569
           begin
570
 
571
                #4;
572
                cmd = 3'b000;
573
                repeat(1)       @(posedge clk2);
574
 
575
                while(flags[0])
576
                   begin
577
                        cmd = 3'b000;
578
                        repeat(2)       @(posedge clk2);
579
                   end
580
 
581
                #2;
582
                if(buffer1[n] !== ep_f_dout)
583
                   begin
584
                        $display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",
585 11 alfoltran
                                buffer1[n], ep_f_dout, $time);
586 2 alfoltran
                        error_cnt = error_cnt + 1;
587
                   end
588
 
589
                cmd = 3'b010;
590
                @(posedge clk2);
591
           end
592
        #1;
593
        cmd = 3'b000;
594
        @(posedge clk2);
595
    end
596
 
597
join
598
 
599
repeat(1)       @(posedge clk);
600
end
601
 
602
cmd = 3'b100;
603
ep_f_addr=32'h0;
604
 
605
show_errors;
606
$display("*****************************************************");
607
$display("*** Test DONE ...                                 ***");
608
$display("*****************************************************\n\n");
609
end
610
endtask
611
 
612
task in3;
613
 
614
reg     [6:0]    my_fa;
615
integer         quick, n, m, rlen,fc;
616
reg     [7:0]    fd;
617
integer         pack_cnt, pack_cnt_max;
618
reg     [7:0]    x;
619
reg     [3:0]    pid;
620
reg     [3:0]    expect_pid;
621
reg     [31:0]   data;
622
reg             pid_cnt;
623
 
624
begin
625
 
626
$display("\n\n");
627
$display("*****************************************************");
628
$display("*** IN ep test 3                                  ***");
629
$display("*****************************************************\n");
630
 
631
send_sof(11'h000 );     // Send SOF
632
 
633
pack_sz_max = 64;
634
pack_cnt_max = 4;
635
 
636
pid_cnt = 0;
637
my_fa = 7'h12;
638
 
639
ep_f_addr=32'h03;
640
cmd=3'b000;
641
 
642
for(pack_sz=0;pack_sz<=pack_sz_max;pack_sz=pack_sz+8)
643
begin
644
 
645
$display("PL size: %0d", pack_sz);
646
 
647
for(pack_cnt=0;pack_cnt<pack_cnt_max;pack_cnt=pack_cnt+1)
648
   begin
649
 
650
        // Fill Buffer
651
        buffer1_last = 0;
652
        for(fc=0;fc<pack_sz;fc=fc+1)
653
           begin
654
                #2;
655
                while(flags[1]) @(posedge clk);
656
 
657
                #1;
658
                //x = fc[7:0];
659
                x = $random;
660
                ep_f_din = x;
661
                buffer0[fc] = x;
662
                cmd = 3'b001;
663
                @(posedge clk);
664
                #1;
665
                cmd = 3'b000;
666
                @(posedge clk);
667
           end
668
        #1;
669
        cmd = 3'b000;
670
        @(posedge clk);
671
 
672
        // Send Data
673
        repeat(1)       @(posedge clk);
674
        send_sof(11'h000 );     // Send SOF
675
        repeat(1)       @(posedge clk);
676
        send_token(     my_fa,          // Function Address
677
                        3,              // Logical Endpoint Number
678
                        `USBF_T_PID_IN  // PID
679
                        );
680
 
681
        repeat(1)       @(posedge clk);
682
 
683
        recv_packet(pid,rlen);
684
 
685
        if(pid_cnt)     expect_pid = 4'hb;
686
        else            expect_pid = 4'h3;
687
 
688
        if(pid !== expect_pid)
689
           begin
690
                $display("ERROR: PID mismatch. Expected: %h, Got: %h (%t)",
691
                        expect_pid, pid, $time);
692
                error_cnt = error_cnt + 1;
693
           end
694
        pid_cnt = ~pid_cnt;
695
 
696
        if(rlen != pack_sz)
697
           begin
698
                $display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
699
                        pack_sz, rlen, $time);
700
                error_cnt = error_cnt + 1;
701
           end
702
 
703
        repeat(4)       @(posedge clk);
704
        send_token(     my_fa,          // Function Address
705
                        3,              // Logical Endpoint Number
706
                        `USBF_T_PID_ACK // PID
707
                        );
708
        repeat(5)       @(posedge clk);
709
 
710
        // Verify Data
711
        for(fc=0;fc<pack_sz;fc=fc+1)
712
           begin
713
                x =  buffer0[fc];
714
                if( (buffer1[fc] !== x) | ( (^buffer1[fc] ^ ^x) === 1'hx) )
715
                   begin
716
                        $display("ERROR: Data (%0d) mismatch. Expected: %h, Got: %h (%t)",
717
                                fc, x, buffer1[fc], $time);
718
                        error_cnt = error_cnt + 1;
719
                   end
720
           end
721
   end
722
 
723
repeat(50)      @(posedge clk);
724
end
725
 
726
cmd = 3'b100;
727
ep_f_addr=32'h0;
728
 
729
show_errors;
730
$display("*****************************************************");
731
$display("*** Test DONE ...                                 ***");
732
$display("*****************************************************\n\n");
733
 
734
end
735
 
736
endtask
737
 
738
task out4;
739
reg     [6:0]    my_fa;
740
reg     [31:0]   data;
741
integer         len, n, no_pack, pl_sz;
742
integer         no_pack_max, pl_sz_max;
743
reg             pid;
744
 
745
reg     [7:0]    x;
746
 
747
begin
748
$display("\n\n");
749
$display("*****************************************************");
750
$display("*** OUT ep test 4                                 ***");
751
$display("*****************************************************\n");
752
 
753
 
754
no_pack_max = 4;        // Number Of packets to transfer
755
pl_sz_max   = 64;       // Payload Size
756
 
757
no_pack = 4;            // Number Of packets to transfer
758
pl_sz = 0;
759
my_fa = 7'h12;
760
 
761
ep_f_addr=32'h04;
762
cmd=3'b000;
763
 
764
for(pl_sz=0;pl_sz<=pl_sz_max;pl_sz=pl_sz+8)
765
begin
766
pid = 0;
767
 
768
$display("PL size: %0d", pl_sz);
769
 
770
for(n=0;n<4096;n=n+1)
771
        //buffer1[n] = $random;
772
        buffer1[n] = n;
773
 
774
buffer1_last = 0;
775
 
776
fork
777
for(no_pack=0;no_pack<no_pack_max;no_pack=no_pack+1)     // Send no_pack Out packets
778
   begin
779
        repeat(1)       @(posedge clk);
780
        send_sof(11'h000 );     // Send SOF
781
        repeat(1)       @(posedge clk);
782
 
783
        send_token(     my_fa,          // Function Address
784
                        4,              // Logical Endpoint Number
785
                        `USBF_T_PID_OUT // PID
786
                        );
787
 
788
        repeat(1)       @(posedge clk);
789
 
790
        if(pid==0)       send_data(`USBF_T_PID_DATA0, pl_sz, 1);
791
        else            send_data(`USBF_T_PID_DATA1, pl_sz, 1);
792
 
793
        pid = ~pid;
794
 
795
        // Wait for ACK
796
        utmi_recv_pack(len);
797
 
798
        if(8'hd2 !== txmem[0])
799
           begin
800
                $display("ERROR: ACK mismatch. Expected: %h, Got: %h (%t)",
801
                8'hd2, txmem[0], $time);
802
                error_cnt = error_cnt + 1;
803
           end
804
 
805
        if(len != 1)
806
           begin
807
                $display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
808
                        pl_sz, len, $time);
809
                error_cnt = error_cnt + 1;
810
           end
811
 
812
        repeat(1)       @(posedge clk);
813
   end
814
 
815
   begin
816
        repeat(10)      @(posedge clk2);
817
        for(n=0;n<(no_pack_max*pl_sz);n=n+1)     // Compare Buffers
818
           begin
819
 
820
                #4;
821
                cmd = 3'b000;
822
                repeat(1)       @(posedge clk2);
823
 
824
                while(flags[0])
825
                   begin
826
                        cmd = 3'b000;
827
                        repeat(2)       @(posedge clk2);
828
                   end
829
 
830 11 alfoltran
                #2;                                     // Comment this line for XILINX Timed Simulation
831
                //@(posedge clk2);      // Comment this line for Standard Simulation
832 2 alfoltran
                if(buffer1[n] !== ep_f_dout)
833
                   begin
834
                        $display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",
835 11 alfoltran
                                buffer1[n], ep_f_dout, $time);
836 2 alfoltran
                        error_cnt = error_cnt + 1;
837
                   end
838
 
839
                cmd = 3'b010;
840
                @(posedge clk2);
841
           end
842
        #1;
843
        cmd = 3'b000;
844
        @(posedge clk2);
845
    end
846
 
847
join
848
 
849
repeat(1)       @(posedge clk);
850
end
851
 
852
cmd=3'b100;
853
ep_f_addr=32'h0;
854
 
855
show_errors;
856
$display("*****************************************************");
857
$display("*** Test DONE ...                                 ***");
858
$display("*****************************************************\n\n");
859
end
860
endtask
861
 
862
task in5;
863
 
864
reg     [6:0]    my_fa;
865
integer         quick, n, m, rlen,fc;
866
reg     [7:0]    fd;
867
integer         pack_cnt, pack_cnt_max;
868
reg     [7:0]    x;
869
reg     [3:0]    pid;
870
reg     [3:0]    expect_pid;
871
reg     [31:0]   data;
872
reg             pid_cnt;
873
 
874
begin
875
 
876
$display("\n\n");
877
$display("*****************************************************");
878
$display("*** IN ep test 5                                  ***");
879
$display("*****************************************************\n");
880
 
881
send_sof(11'h000 );     // Send SOF
882
 
883
pack_sz_max = 64;
884
pack_cnt_max = 4;
885
 
886
pid_cnt = 0;
887
my_fa = 7'h12;
888
 
889
ep_f_addr=32'h05;
890
cmd=3'b000;
891
 
892
for(pack_sz=0;pack_sz<=pack_sz_max;pack_sz=pack_sz+8)
893
begin
894
 
895
$display("PL size: %0d", pack_sz);
896
 
897
for(pack_cnt=0;pack_cnt<pack_cnt_max;pack_cnt=pack_cnt+1)
898
   begin
899
 
900
        // Fill Buffer
901
        buffer1_last = 0;
902
        for(fc=0;fc<pack_sz;fc=fc+1)
903
           begin
904
                #2;
905
                while(flags[1]) @(posedge clk);
906
 
907
                #1;
908
                //x = fc[7:0];
909
                x = $random;
910
                ep_f_din = x;
911
                buffer0[fc] = x;
912
                cmd = 3'b001;
913
                @(posedge clk);
914
                #1;
915
                cmd = 3'b000;
916
                @(posedge clk);
917
           end
918
        #1;
919
        cmd = 3'b000;
920
        @(posedge clk);
921
 
922
        // Send Data
923
        repeat(1)       @(posedge clk);
924
        send_sof(11'h000 );     // Send SOF
925
        repeat(1)       @(posedge clk);
926
        send_token(     my_fa,          // Function Address
927
                        5,              // Logical Endpoint Number
928
                        `USBF_T_PID_IN  // PID
929
                        );
930
 
931
        repeat(1)       @(posedge clk);
932
 
933
        recv_packet(pid,rlen);
934
 
935
        if (pack_sz == 0)        expect_pid = 4'ha;
936
        else if(pid_cnt)        expect_pid = 4'hb;
937
        else                    expect_pid = 4'h3;
938
 
939
        if(pid !== expect_pid)
940
           begin
941
                $display("ERROR: PID mismatch. Expected: %h, Got: %h (%t)",
942
                        expect_pid, pid, $time);
943
                error_cnt = error_cnt + 1;
944
           end
945
        pid_cnt = ~pid_cnt;
946
 
947
        if(rlen != pack_sz)
948
           begin
949
                $display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
950
                        pack_sz, rlen, $time);
951
                error_cnt = error_cnt + 1;
952
           end
953
 
954
        repeat(4)       @(posedge clk);
955
 
956 6 alfoltran
        if(pack_sz != 0)
957
           begin
958
                send_token(     my_fa,          // Function Address
959
                                5,              // Logical Endpoint Number
960
                                `USBF_T_PID_ACK // PID
961
                                );
962
                repeat(5)       @(posedge clk);
963
           end
964
 
965 2 alfoltran
        // Verify Data
966
        for(fc=0;fc<pack_sz;fc=fc+1)
967
           begin
968
                x =  buffer0[fc];
969
                if( (buffer1[fc] !== x) | ( (^buffer1[fc] ^ ^x) === 1'hx) )
970
                   begin
971
                        $display("ERROR: Data (%0d) mismatch. Expected: %h, Got: %h (%t)",
972
                                fc, x, buffer1[fc], $time);
973
                        error_cnt = error_cnt + 1;
974
                   end
975
           end
976
   end
977
 
978
repeat(50)      @(posedge clk);
979
end
980
 
981
cmd=3'b100;
982
ep_f_addr=32'h0;
983
 
984
show_errors;
985
$display("*****************************************************");
986
$display("*** Test DONE ...                                 ***");
987
$display("*****************************************************\n\n");
988
 
989
end
990
 
991
endtask
992
 
993
task out6;
994
reg     [6:0]    my_fa;
995
reg     [31:0]   data;
996
integer         len, n, no_pack, pl_sz;
997
integer         no_pack_max, pl_sz_max;
998
reg             pid;
999
 
1000
reg     [7:0]    x;
1001
 
1002
begin
1003
$display("\n\n");
1004
$display("*****************************************************");
1005
$display("*** OUT ep test 6                                 ***");
1006
$display("*****************************************************\n");
1007
 
1008
 
1009
no_pack_max = 4;        // Number Of packets to transfer
1010
pl_sz_max   = 64;       // Payload Size
1011
 
1012
no_pack = 4;            // Number Of packets to transfer
1013
pl_sz = 0;
1014
my_fa = 7'h12;
1015
 
1016
ep_f_addr=32'h06;
1017
cmd=3'b000;
1018
 
1019
for(pl_sz=0;pl_sz<=pl_sz_max;pl_sz=pl_sz+8)
1020
begin
1021
pid = 0;
1022
 
1023
$display("PL size: %0d", pl_sz);
1024
 
1025
for(n=0;n<4096;n=n+1)
1026
        //buffer1[n] = $random;
1027
        buffer1[n] = n;
1028
 
1029
buffer1_last = 0;
1030
 
1031
fork
1032
for(no_pack=0;no_pack<no_pack_max;no_pack=no_pack+1)     // Send no_pack Out packets
1033
   begin
1034
        repeat(1)       @(posedge clk);
1035
        send_sof(11'h000 );     // Send SOF
1036
        repeat(1)       @(posedge clk);
1037
 
1038
        send_token(     my_fa,          // Function Address
1039
                        6,              // Logical Endpoint Number
1040
                        `USBF_T_PID_OUT // PID
1041
                        );
1042
 
1043
        repeat(1)       @(posedge clk);
1044
 
1045
        if(pid==0)       send_data(`USBF_T_PID_DATA0, pl_sz, 1);
1046
        else            send_data(`USBF_T_PID_DATA1, pl_sz, 1);
1047
 
1048
        pid = ~pid;
1049
 
1050
        // Wait for ACK
1051
        utmi_recv_pack(len);
1052
 
1053
        if(8'hd2 !== txmem[0])
1054
           begin
1055
                $display("ERROR: ACK mismatch. Expected: %h, Got: %h (%t)",
1056
                8'hd2, txmem[0], $time);
1057
                error_cnt = error_cnt + 1;
1058
           end
1059
 
1060
        if(len != 1)
1061
           begin
1062
                $display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
1063
                        pl_sz, len, $time);
1064
                error_cnt = error_cnt + 1;
1065
           end
1066
 
1067
        repeat(1)       @(posedge clk);
1068
   end
1069
 
1070
   begin
1071
        repeat(10)      @(posedge clk2);
1072
        for(n=0;n<(no_pack_max*pl_sz);n=n+1)     // Compare Buffers
1073
           begin
1074
 
1075
                #4;
1076
                cmd = 3'b000;
1077
                repeat(1)       @(posedge clk2);
1078
 
1079
                while(flags[0])
1080
                   begin
1081
                        cmd = 3'b000;
1082
                        repeat(2)       @(posedge clk2);
1083
                   end
1084
 
1085 11 alfoltran
                #2;                                     // Comment this line for XILINX Timed Simulation
1086
                //@(posedge clk2);      // Comment this line for Standard Simulation
1087 2 alfoltran
                if(buffer1[n] !== ep_f_dout)
1088
                   begin
1089
                        $display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",
1090 11 alfoltran
                                buffer1[n], ep_f_dout, $time);
1091 2 alfoltran
                        error_cnt = error_cnt + 1;
1092
                   end
1093
 
1094
                cmd = 3'b010;
1095
                @(posedge clk2);
1096
           end
1097
        #1;
1098
        cmd = 3'b000;
1099
        @(posedge clk2);
1100
    end
1101
 
1102
join
1103
 
1104
repeat(1)       @(posedge clk);
1105
end
1106
 
1107
cmd=3'b100;
1108
ep_f_addr=8'h0;
1109
 
1110
show_errors;
1111
$display("*****************************************************");
1112
$display("*** Test DONE ...                                 ***");
1113
$display("*****************************************************\n\n");
1114
end
1115
endtask
1116
 

powered by: WebSVN 2.1.0

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