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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_7/] [apps/] [test/] [bench/] [verilog/] [test_bench.v] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 93 mihad
`include "timescale.v"
2
`include "pci_testbench_defines.v"
3
 
4
`define TIME $display("Time %t", $time)
5
`define ERROR(TEXT) $display("*E, %s", TEXT)
6
`define INVALID_DATA(FROM) $display("*E, Data read from %s not as expected!", FROM)
7
`define VALUES(EXPECTED,ACTUAL) $display("Expected %h, Actual %h", EXPECTED, ACTUAL)
8
 
9
module test_bench
10
(
11
);
12
 
13
 
14
reg clk,
15
    rst ;
16
 
17
assign glbl.GSR = rst ;
18
 
19
wire wbm_cyc_o,
20
     wbm_stb_o,
21
     wbm_cab_o,
22
     wbm_we_o ;
23
 
24
wire [31:0] wbm_adr_o ;
25
wire [3:0]  wbm_sel_o ;
26
 
27
wire [31:0] wbm_dat_o,
28
            wbm_dat_i ;
29
 
30
wire wbm_ack_i,
31
     wbm_rty_i,
32
     wbm_err_i ;
33
 
34
wire wbs_cyc_i,
35
     wbs_stb_i,
36
     wbs_cab_i,
37
     wbs_we_i ;
38
 
39
wire [31:0] wbs_adr_i ;
40
wire [3:0]  wbs_sel_i ;
41
 
42
wire [31:0] wbs_dat_i,
43
            wbs_dat_o ;
44
 
45
wire wbs_ack_o,
46
     wbs_rty_o,
47
     wbs_err_o ;
48
 
49
reg pci_clk,
50
    pci_irdy_reg,
51
    pci_irdy_en_reg,
52
    pci_trdy_reg ;
53
 
54
reg [31:0] pci_ad_reg ;
55
 
56
test i_test
57
(
58
    .clk_i      (clk),
59
    .rst_i      (rst),
60
 
61
    .pci_clk_i  (pci_clk),
62
 
63
    .wbm_cyc_o  (wbm_cyc_o),
64
    .wbm_stb_o  (wbm_stb_o),
65
    .wbm_cab_o  (wbm_cab_o),
66
    .wbm_we_o   (wbm_we_o ),
67
    .wbm_adr_o  (wbm_adr_o),
68
    .wbm_sel_o  (wbm_sel_o),
69
    .wbm_dat_o  (wbm_dat_o),
70
    .wbm_dat_i  (wbm_dat_i),
71
    .wbm_ack_i  (wbm_ack_i),
72
    .wbm_rty_i  (wbm_rty_i),
73
    .wbm_err_i  (wbm_err_i),
74
 
75
    .wbs_cyc_i  (wbs_cyc_i),
76
    .wbs_stb_i  (wbs_stb_i),
77
    .wbs_cab_i  (wbs_cab_i),
78
    .wbs_we_i   (wbs_we_i ),
79
    .wbs_adr_i  (wbs_adr_i),
80
    .wbs_sel_i  (wbs_sel_i),
81
    .wbs_dat_i  (wbs_dat_i),
82
    .wbs_dat_o  (wbs_dat_o),
83
    .wbs_ack_o  (wbs_ack_o),
84
    .wbs_rty_o  (wbs_rty_o),
85
    .wbs_err_o  (wbs_err_o),
86
 
87
    .pci_irdy_reg_i    (pci_irdy_reg),
88
    .pci_irdy_en_reg_i (pci_irdy_en_reg),
89
    .pci_trdy_reg_i    (pci_trdy_reg),
90
    .pci_ad_reg_i      (pci_ad_reg)
91
);
92
 
93
WB_MASTER_BEHAVIORAL wishbone_master
94
(
95
    .CLK_I(clk),
96
    .RST_I(rst),
97
    .TAG_I(`WB_TAG_WIDTH'h0),
98
    .TAG_O(),
99
    .ACK_I(wbs_ack_o),
100
    .ADR_O(wbs_adr_i),
101
    .CYC_O(wbs_cyc_i),
102
    .DAT_I(wbs_dat_o),
103
    .DAT_O(wbs_dat_i),
104
    .ERR_I(1'b0),
105
    .RTY_I(1'b0),
106
    .SEL_O(wbs_sel_i),
107
    .STB_O(wbs_stb_i),
108
    .WE_O (wbs_we_i),
109
    .CAB_O(wbs_cab_i)
110
);
111
 
112
WB_SLAVE_BEHAVIORAL wishbone_slave
113
(
114
    .CLK_I              (clk),
115
    .RST_I              (rst),
116
    .ACK_O              (wbm_ack_i),
117
    .ADR_I              (wbm_adr_o),
118
    .CYC_I              (wbm_cyc_o),
119
    .DAT_O              (wbm_dat_i),
120
    .DAT_I              (wbm_dat_o),
121
    .ERR_O              (),
122
    .RTY_O              (),
123
    .SEL_I              (wbm_sel_o),
124
    .STB_I              (wbm_stb_o),
125
    .WE_I               (wbm_we_o),
126
    .CAB_I              (wbm_cab_o)
127
);
128
 
129
integer wbs_mon_log_file_desc, wbm_mon_log_file_desc ;
130
 
131
WB_BUS_MON wbs_wb_mon(
132
                    .CLK_I(clk),
133
                    .RST_I(rst),
134
                    .ACK_I(wbs_ack_o),
135
                    .ADDR_O(wbs_adr_i),
136
                    .CYC_O(wbs_cyc_i),
137
                    .DAT_I(wbs_dat_o),
138
                    .DAT_O(wbs_dat_i),
139
                    .ERR_I(1'b0),
140
                    .RTY_I(1'b0),
141
                    .SEL_O(wbs_sel_i),
142
                    .STB_O(wbs_stb_i),
143
                    .WE_O (wbs_we_i),
144
                    .TAG_I( `WB_TAG_WIDTH'h0 ),
145
                    .TAG_O(),
146
                    .CAB_O(wbs_cab_i),
147
                    .log_file_desc ( wbs_mon_log_file_desc )
148
                  ) ;
149
 
150
WB_BUS_MON wbm_wb_mon(
151
                    .CLK_I(clk),
152
                    .RST_I(rst),
153
                    .ACK_I(wbm_ack_i),
154
                    .ADDR_O(wbm_adr_o),
155
                    .CYC_O(wbm_cyc_o),
156
                    .DAT_I(wbm_dat_i),
157
                    .DAT_O(wbm_dat_o),
158
                    .ERR_I(1'b0),
159
                    .RTY_I(1'b0),
160
                    .SEL_O(wbm_sel_o),
161
                    .STB_O(wbm_stb_o),
162
                    .WE_O (wbm_we_o),
163
                    .TAG_I( `WB_TAG_WIDTH'h0 ),
164
                    .TAG_O(),
165
                    .CAB_O(wbm_cab_o),
166
                    .log_file_desc ( wbm_mon_log_file_desc )
167
                  ) ;
168
 
169
 
170
// clock generation
171
always
172
    #(10) clk = ~clk ;
173
 
174
always
175
    #15 pci_clk = ~pci_clk ;
176
 
177
integer wb_master_waits ;
178
initial
179
begin
180
    wbs_mon_log_file_desc = $fopen("../log/wbs_mon.log") ;
181
    wbm_mon_log_file_desc = $fopen("../log/wbm_mon.log") ;
182
    clk = 1'b1 ;
183
    rst = 1'b1 ;
184
 
185
    pci_clk         = 1'b1 ;
186
    pci_irdy_reg    = 1'b1 ;
187
    pci_irdy_en_reg = 1'b1 ;
188
    pci_trdy_reg    = 1'b1 ;
189
    pci_ad_reg      = 0 ;
190
 
191
    wb_master_waits = 0 ;
192
 
193
    repeat(10)
194
        @(posedge clk) ;
195
 
196
    rst <= 1'b0 ;
197
 
198
    run_tests ;
199
 
200
    $stop ;
201
end
202
 
203
task run_tests ;
204
begin
205
/*
206
    wbs_fill_with_singles(0) ;
207
    wbs_check_data_with_singles(0) ;
208
 
209
    wbs_fill_with_singles(1) ;
210
    wbs_check_data_with_bursts(1, 1024) ;
211
 
212
    wbs_fill_with_bursts(0, 2) ;
213
    wbs_check_data_with_singles(0) ;
214
 
215
    wbs_fill_with_bursts(1, 4) ;
216
    wbs_check_data_with_bursts(1, 2) ;
217
 
218
    wbs_fill_with_singles(2) ;
219
    wbs_check_data_with_bursts(2, 16) ;
220
 
221
    wbs_fill_with_bursts(3, 64) ;
222
    wbs_check_data_with_bursts(3, 128) ;
223
 
224
    test_master_writes ;
225
    test_master_reads ;
226
 
227
    test_slave_error_detection ;
228
 
229
    test_master_transaction_counts ;
230
*/
231
    test_master_data_errors ;
232
end
233
endtask
234
 
235
task wbs_fill_with_singles ;
236
    input [3:0] pattern_select ;
237
    integer i ;
238
    reg [31:0] current_data ;
239
    reg [31:0] current_address ;
240
begin
241
    current_address = 0 ;
242
 
243
    current_data = get_first_data(pattern_select) ;
244
 
245
    for (i = 0 ; i < 1024 ; i = i + 1)
246
    begin
247
        wb_master_single_write(current_address, current_data) ;
248
        current_data = get_next_data (pattern_select, current_data) ;
249
        current_address = current_address + 4 ;
250
    end
251
end
252
endtask
253
 
254
task wbs_fill_with_bursts ;
255
    input [3:0]  pattern_select ;
256
    input [31:0] burst_sizes ;
257
 
258
    integer i ;
259
    reg [31:0] current_data ;
260
    reg [31:0] current_address ;
261
 
262
    reg `WRITE_STIM_TYPE   write_data ;
263
begin
264
    current_address = 0 ;
265
 
266
    write_data = 0 ;
267
 
268
    write_data`WRITE_SEL = 4'hF ;
269
 
270
    current_data = get_first_data (pattern_select) ;
271
 
272
    for (i = 0 ; i < 1024 ; i = i + 1)
273
    begin
274
 
275
        write_data`WRITE_ADDRESS = current_address ;
276
        write_data`WRITE_DATA    = current_data ;
277
 
278
        wishbone_master.blk_write_data[i % burst_sizes] = write_data ;
279
 
280
        if ((i % burst_sizes) == (burst_sizes - 1))
281
            wb_master_burst_write(burst_sizes) ;
282
 
283
        current_address = current_address + 4 ;
284
        current_data = get_next_data(pattern_select, current_data) ;
285
    end
286
end
287
endtask
288
 
289
task wbs_check_data_with_singles ;
290
    input [3:0] pattern_select ;
291
 
292
    integer i ;
293
    reg [31:0] current_data ;
294
    reg [31:0] current_address ;
295
begin
296
    current_address = 0 ;
297
 
298
    current_data = get_first_data(pattern_select) ;
299
 
300
    for (i = 0 ; i < 1024 ; i = i + 1)
301
    begin
302
 
303
        wb_master_single_read(current_address, current_data) ;
304
        current_address = current_address + 4 ;
305
        current_data    = get_next_data(pattern_select, current_data) ;
306
    end
307
end
308
endtask
309
 
310
task wb_master_single_write ;
311
    input [31:0] adr_i ;
312
    input [31:0] data_i ;
313
 
314
    reg `WRITE_STIM_TYPE   write_data ;
315
    reg `WRITE_RETURN_TYPE write_status ;
316
    reg `WB_TRANSFER_FLAGS write_flags ;
317
begin
318
    write_flags = 0 ;
319
    write_flags`INIT_WAITS   = wb_master_waits ;
320
    write_flags`SUBSEQ_WAITS = wb_master_waits ;
321
 
322
    write_data  = 0 ;
323
 
324
    write_data`WRITE_DATA    = data_i ;
325
    write_data`WRITE_ADDRESS = adr_i ;
326
    write_data`WRITE_SEL     = 4'hF ;
327
 
328
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
329
 
330
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
331
    begin
332
        `TIME ;
333
        `ERROR("Single writes must always be succesfull") ;
334
        $stop ;
335
    end
336
end
337
endtask // wb_master_single_write
338
 
339
task wb_master_burst_write ;
340
    input [31:0] size_i ;
341
 
342
    reg `WRITE_RETURN_TYPE write_status ;
343
    reg `WB_TRANSFER_FLAGS write_flags ;
344
 
345
    integer i ;
346
begin
347
    write_flags = 0 ;
348
    write_flags`WB_TRANSFER_SIZE = size_i ;
349
    write_flags`WB_TRANSFER_CAB  = 1'b1 ;
350
 
351
    write_flags`INIT_WAITS   = wb_master_waits ;
352
    write_flags`SUBSEQ_WAITS = wb_master_waits ;
353
 
354
    wishbone_master.wb_block_write( write_flags, write_status ) ;
355
 
356
    if (write_status`CYC_ACTUAL_TRANSFER !== size_i)
357
    begin
358
        `TIME ;
359
        `ERROR("Burst writes must always be succesfull") ;
360
        $stop ;
361
    end
362
end
363
endtask // wb_master_single_write
364
 
365
task wb_master_single_read ;
366
    input [31:0] adr_i ;
367
    input [31:0] data_i ;
368
 
369
    reg `READ_STIM_TYPE   read_data ;
370
    reg `READ_RETURN_TYPE read_status ;
371
    reg `WB_TRANSFER_FLAGS read_flags ;
372
begin
373
    read_flags = 0 ;
374
    read_data  = 0 ;
375
 
376
    read_data`READ_ADDRESS = adr_i ;
377
    read_data`READ_SEL     = 4'hF ;
378
 
379
    read_flags`INIT_WAITS   = wb_master_waits ;
380
    read_flags`SUBSEQ_WAITS = wb_master_waits ;
381
 
382
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
383
 
384
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
385
    begin
386
        `TIME ;
387
        `ERROR("Single reads must always be succesfull") ;
388
        $stop ;
389
    end
390
 
391
    if (read_status`READ_DATA !== data_i)
392
    begin
393
        `TIME ;
394
        `INVALID_DATA("Test module") ;
395
        `VALUES(data_i, read_status`READ_DATA) ;
396
        $stop ;
397
    end
398
end
399
endtask // wb_master_single_read
400
 
401
task wb_master_burst_read ;
402
    input [31:0] size_i ;
403
 
404
    reg `READ_RETURN_TYPE read_status ;
405
    reg `WB_TRANSFER_FLAGS read_flags ;
406
begin
407
    read_flags = 0 ;
408
 
409
    read_flags`WB_TRANSFER_SIZE = size_i ;
410
    read_flags`WB_TRANSFER_CAB  = 1'b1 ;
411
 
412
    read_flags`INIT_WAITS   = wb_master_waits ;
413
    read_flags`SUBSEQ_WAITS = wb_master_waits ;
414
 
415
    wishbone_master.wb_block_read( read_flags, read_status ) ;
416
 
417
    if (read_status`CYC_ACTUAL_TRANSFER !== size_i)
418
    begin
419
        `TIME ;
420
        `ERROR("Burst reads must always be succesfull") ;
421
        $stop ;
422
    end
423
 
424
end
425
endtask // wb_master_burst_read
426
 
427
task wbs_check_data_with_bursts ;
428
    input [3:0]  pattern_select ;
429
    input [31:0] burst_sizes ;
430
 
431
    integer i ;
432
    reg [31:0] current_data ;
433
    reg [31:0] current_address ;
434
 
435
    reg `READ_RETURN_TYPE read_status ;
436
    reg `READ_STIM_TYPE   read_data ;
437
 
438
    integer j ;
439
begin
440
    current_address = 0 ;
441
 
442
    read_data          = 0 ;
443
    read_data`READ_SEL = 4'hF ;
444
 
445
    current_data = get_first_data(pattern_select) ;
446
 
447
    for (i = 0 ; i < 1024 ; i = i + 1)
448
    begin
449
        read_data`READ_ADDRESS = current_address ;
450
        wishbone_master.blk_read_data_in[i % burst_sizes] = read_data ;
451
 
452
        if ((i % burst_sizes) == (burst_sizes - 1))
453
        begin
454
            wb_master_burst_read(burst_sizes) ;
455
            for (j = 0 ; j <= (i % burst_sizes) ; j = j + 1)
456
            begin
457
                read_status = wishbone_master.blk_read_data_out[j] ;
458
                if (read_status`READ_DATA !== current_data)
459
                begin
460
                    `TIME ;
461
                    `INVALID_DATA("Test module") ;
462
                    `VALUES(current_data, read_status`READ_DATA) ;
463
                    $stop ;
464
                end
465
 
466
                current_data = get_next_data(pattern_select, current_data) ;
467
            end
468
        end
469
 
470
        current_address = current_address + 4 ;
471
    end
472
end
473
endtask
474
 
475
task test_slave_error_detection ;
476
    integer i ;
477
    integer current_test_size ;
478
    reg [10:0] offset_for_dat_err ;
479
    reg [10:0] offset_for_adr_err ;
480
 
481
    reg `WRITE_STIM_TYPE   write_data ;
482
    reg `WRITE_RETURN_TYPE write_status ;
483
    reg `WB_TRANSFER_FLAGS write_flags ;
484
 
485
    reg [31:0] current_start_address ;
486
    reg [31:0] current_start_data ;
487
 
488
    reg [31:0] current_address ;
489
    reg [31:0] current_data ;
490
 
491
    reg [9:0]  current_data_error_offset ;
492
    reg [9:0]  current_address_error_offset ;
493
begin
494
 
495
    write_flags = 0 ;
496
    write_flags`INIT_WAITS   = wb_master_waits ;
497
    write_flags`SUBSEQ_WAITS = wb_master_waits ;
498
 
499
    write_data  = 0 ;
500
 
501
    write_data`WRITE_SEL     = 4'hF ;
502
 
503
    for (current_test_size = 1 ; current_test_size <= 1024 ; current_test_size = current_test_size * 'd2)
504
    begin
505
 
506
        // select random address
507
        current_start_address       = $random ;
508
        // set the right offset in the 4KB space
509
        current_start_address[11:0] = ('d1024 - current_test_size) * 4 ;
510
        // set 13th bit to 0 to select internal rams not registers!
511
        current_start_address[12]   = 1'b0 ;
512
 
513
        current_start_data = $random ;
514
 
515
        current_data    = current_start_data ;
516
        current_address = current_start_address ;
517
 
518
        for (i = 0 ; i < current_test_size ; i = i + 1)
519
        begin
520
            write_data`WRITE_DATA    = current_data ;
521
            write_data`WRITE_ADDRESS = current_address ;
522
            wishbone_master.blk_write_data[i] = write_data ;
523
 
524
            current_data    = {current_data[30:0], current_data[31]} ;
525
            current_address = current_address + 4 ;
526
        end
527
 
528
        // put in the last write out of sequence
529
        write_data`WRITE_ADDRESS = current_start_address ;
530
        write_data`WRITE_DATA    = current_start_data ;
531
        wishbone_master.blk_write_data[i] = write_data ;
532
 
533
        write_flags`WB_TRANSFER_SIZE = current_test_size + 1;
534
 
535
        configure_slave_registers
536
        (
537
            current_start_address,      // start_adr
538
            current_start_data,         // start_dat
539
            current_test_size[10:0],    // test_size
540
            1'b1,                       // clear_burst_cnt
541
            1'b1                        // clear_errors
542
        ) ;
543
 
544
        wishbone_master.wb_block_write(write_flags, write_status) ;
545
        if (write_status`CYC_ACTUAL_TRANSFER !== current_test_size + 1)
546
        begin
547
            `TIME ;
548
            `ERROR("Block writes must always be succesfull") ;
549
            $stop ;
550
        end
551
 
552
        // now test for errors - non should be detected
553
        check_slave_errors
554
        (
555
            1'b0,   // expect_adr_err
556
            1'b0    // expect_dat_err
557
        ) ;
558
 
559
        // repeat same thing with one single data sequence error
560
        current_data_error_offset    = current_test_size - 1 ;
561
        write_data   = wishbone_master.blk_write_data[current_data_error_offset] ;
562
        current_data = write_data`WRITE_DATA ;
563
 
564
        // change the value in the data sequence
565
        current_data                                              = {current_data[0], current_data[31:1]} ;
566
        write_data`WRITE_DATA                                     = current_data ;
567
        wishbone_master.blk_write_data[current_data_error_offset] = write_data ;
568
 
569
        configure_slave_registers
570
        (
571
            current_start_address,      // start_adr
572
            current_start_data,         // start_dat
573
            current_test_size[10:0],    // test_size
574
            1'b0,                       // clear_burst_cnt
575
            1'b0                        // clear_errors
576
        ) ;
577
 
578
        write_flags`WB_TRANSFER_SIZE = current_test_size ;
579
 
580
        wishbone_master.wb_block_write(write_flags, write_status) ;
581
        if (write_status`CYC_ACTUAL_TRANSFER !== current_test_size)
582
        begin
583
            `TIME ;
584
            `ERROR("Block writes must always be succesfull") ;
585
            $stop ;
586
        end
587
 
588
        // now test for errors - data error should be detected
589
        check_slave_errors
590
        (
591
            1'b0,   // expect_adr_err
592
            1'b1    // expect_dat_err
593
        ) ;
594
 
595
        // repair the data
596
        current_data = {current_data[30:0], current_data[31]} ;
597
        write_data`WRITE_DATA = current_data ;
598
        wishbone_master.blk_write_data[current_data_error_offset] = write_data ;
599
 
600
        // repeat same thing with one single address sequence error
601
        current_address_error_offset = 0 ;
602
        write_data = wishbone_master.blk_write_data[current_address_error_offset] ;
603
        current_address = write_data`WRITE_ADDRESS ;
604
        current_address[11:2] = current_address[11:2] - 1'b1 ;
605
        write_data`WRITE_ADDRESS = current_address ;
606
        wishbone_master.blk_write_data[current_address_error_offset] = write_data ;
607
 
608
        configure_slave_registers
609
        (
610
            current_start_address,      // start_adr
611
            current_start_data,         // start_dat
612
            current_test_size[10:0],    // test_size
613
            1'b0,                       // clear_burst_cnt
614
            1'b1                        // clear_errors
615
        ) ;
616
 
617
        wishbone_master.wb_block_write(write_flags, write_status) ;
618
        if (write_status`CYC_ACTUAL_TRANSFER !== current_test_size)
619
        begin
620
            `TIME ;
621
            `ERROR("Block writes must always be succesfull") ;
622
            $stop ;
623
        end
624
 
625
        // now test for errors - address error should be detected
626
        check_slave_errors
627
        (
628
            1'b1,   // expect_adr_err
629
            1'b0    // expect_dat_err
630
        ) ;
631
 
632
        // repair the address
633
        current_address[11:2] = current_address[11:2] + 1'b1 ;
634
        write_data`WRITE_ADDRESS = current_address ;
635
        wishbone_master.blk_write_data[current_address_error_offset] = write_data ;
636
 
637
 
638
        // repeat same thing with both errors
639
 
640
        current_data_error_offset    = 0 ;
641
        current_address_error_offset = current_test_size - 1;
642
 
643
        write_data = wishbone_master.blk_write_data[current_address_error_offset] ;
644
        current_address = write_data`WRITE_ADDRESS ;
645
        current_address[11:2] = current_address[11:2] + 1'b1 ;
646
        write_data`WRITE_ADDRESS = current_address ;
647
        wishbone_master.blk_write_data[current_address_error_offset] = write_data ;
648
 
649
        write_data   = wishbone_master.blk_write_data[current_data_error_offset] ;
650
        current_data = write_data`WRITE_DATA ;
651
 
652
        // change the value in the data sequence
653
        current_data                                              = {current_data[30:0], current_data[31]} ;
654
        write_data`WRITE_DATA                                     = current_data ;
655
        wishbone_master.blk_write_data[current_data_error_offset] = write_data ;
656
 
657
        configure_slave_registers
658
        (
659
            current_start_address,      // start_adr
660
            current_start_data,         // start_dat
661
            current_test_size[10:0],    // test_size
662
            1'b0,                       // clear_burst_cnt
663
            1'b1                        // clear_errors
664
        ) ;
665
 
666
        wishbone_master.wb_block_write(write_flags, write_status) ;
667
        if (write_status`CYC_ACTUAL_TRANSFER !== current_test_size)
668
        begin
669
            `TIME ;
670
            `ERROR("Block writes must always be succesfull") ;
671
            $stop ;
672
        end
673
 
674
        // now test for errors - address error should be detected
675
        check_slave_errors
676
        (
677
            1'b1,   // expect_adr_err
678
            1'b1    // expect_dat_err
679
        ) ;
680
 
681
        // now do test without errors and check if error statuses remain set
682
        write_data = wishbone_master.blk_write_data[current_address_error_offset] ;
683
        current_address = write_data`WRITE_ADDRESS ;
684
        current_address[11:2] = current_address[11:2] - 1'b1 ;
685
        write_data`WRITE_ADDRESS = current_address ;
686
        wishbone_master.blk_write_data[current_address_error_offset] = write_data ;
687
 
688
        write_data   = wishbone_master.blk_write_data[current_data_error_offset] ;
689
        current_data = write_data`WRITE_DATA ;
690
 
691
        // change the value in the data sequence
692
        current_data                                              = {current_data[0], current_data[31:1]} ;
693
        write_data`WRITE_DATA                                     = current_data ;
694
        wishbone_master.blk_write_data[current_data_error_offset] = write_data ;
695
 
696
        configure_slave_registers
697
        (
698
            current_start_address,      // start_adr
699
            current_start_data,         // start_dat
700
            current_test_size[10:0],    // test_size
701
            1'b0,                       // clear_burst_cnt
702
            1'b0                        // clear_errors
703
        ) ;
704
 
705
        wishbone_master.wb_block_write(write_flags, write_status) ;
706
        if (write_status`CYC_ACTUAL_TRANSFER !== current_test_size)
707
        begin
708
            `TIME ;
709
            `ERROR("Block writes must always be succesfull") ;
710
            $stop ;
711
        end
712
 
713
        // now test for errors - address error should be detected
714
        check_slave_errors
715
        (
716
            1'b1,   // expect_adr_err
717
            1'b1    // expect_dat_err
718
        ) ;
719
 
720
 
721
    end
722
end
723
endtask // test_slave_error_detection
724
 
725
task test_master_transaction_counts ;
726
    integer i ;
727
    reg     ok_wb ;
728
    reg [2:0] wait_cycles ;
729
    integer num_of_transactions ;
730
    reg [31:0] current_address ;
731
begin
732
    wait_cycles = 0 ;
733
    for (i = 1 ; i <= 4096 ; i = i * 2)
734
    begin
735
        if (i <= 1024)
736
            num_of_transactions = 1 ;
737
 
738
        if (i == 2048)
739
            num_of_transactions = 2 ;
740
 
741
        if (i == 4096)
742
            num_of_transactions = 4 ;
743
 
744
        configure_master_registers
745
        (
746
            i / num_of_transactions,    //transaction_size
747
            1,                          //opcode
748
            0,                          //base_address
749
            1,                          //clear_transaction_counts
750
            0,                          //initiate_test
751
            0,                          //test size
752
 
753
        );
754
 
755
        current_address = 0 ;
756
        fork
757
        begin
758
            wishbone_slave.cycle_response({1'b0, 1'b0, 1'b0}, wait_cycles, 0) ;
759
            fork
760
            begin
761
                activate_master(num_of_transactions) ;
762
                wishbone_slave.cycle_response({1'b1, 1'b0, 1'b0}, wait_cycles, 0) ;
763
            end
764
                repeat (num_of_transactions)
765
                begin
766
                    wb_transaction_progress_monitor
767
                    (
768
                        current_address,            // address
769
                        1'b1,                       // write
770
                        i / num_of_transactions,    // num_of_transfers
771
                        1'b1,                       // check_transfers
772
                        ok_wb                       // ok
773
                    ) ;
774
 
775
                    if (ok_wb !== 1'b1)
776
                    begin
777
                        `TIME ;
778
                        `ERROR("Transaction progress monitor detected invalid transaction!") ;
779
                        $stop ;
780
                    end
781
                    current_address = current_address + 4096 ;
782
                end
783
            join
784
        end
785
        begin
786
            @(posedge clk) ;
787
            while(~wbm_cyc_o | ~wbm_stb_o | ~wbm_ack_i)
788
                @(posedge clk) ;
789
 
790
            repeat(2)
791
                @(posedge pci_clk) ;
792
 
793
            pci_irdy_reg    <= 1'b1 ;
794
            pci_irdy_en_reg <= 1'b1 ;
795
            pci_trdy_reg    <= 1'b0 ;
796
 
797
            repeat(i)
798
            begin
799
                repeat (wait_cycles)
800
                begin
801
                    @(posedge pci_clk) ;
802
                    pci_irdy_reg <= 1'b1 ;
803
                end
804
 
805
                @(posedge pci_clk) ;
806
                pci_irdy_reg    <= 1'b0 ;
807
                pci_irdy_en_reg <= 1'b1 ;
808
                pci_trdy_reg    <= 1'b0 ;
809
            end
810
 
811
            @(posedge pci_clk) ;
812
            pci_irdy_reg <= 1'b1 ;
813
        end
814
        join
815
 
816
        // check numbers of transactions recorded
817
        wb_master_single_read(32'hFFFF_F024, i) ;
818
        wb_master_single_read(32'h0000_1028, i) ;
819
 
820
        wait_cycles = wait_cycles + 1 ;
821
    end
822
end
823
endtask // test_master_transaction_counts
824
 
825
task test_master_data_errors ;
826
    integer i ;
827
    integer current_error_offset ;
828
    integer num_of_transfers ;
829
    reg [31:0] tmp ;
830
begin
831
    for (i = 1 ; i <= 4096 ; i = i * 2)
832
    begin
833
        pci_ad_reg = get_first_data(3) ;
834
        configure_master_registers
835
        (
836
            0,          //transaction_size
837
            1,          //opcode
838
            0,          //base_address
839
            1,          //clear_transaction_counts
840
            1,          //initiate_test
841
            i,          //test size
842
            pci_ad_reg  //start_dat
843
        );
844
 
845
        @(posedge pci_clk) ;
846
        pci_irdy_reg    <= 1'b0 ;
847
        pci_irdy_en_reg <= 1'b1 ;
848
        pci_trdy_reg    <= 1'b0 ;
849
 
850
        repeat(i)
851
        begin
852
            @(posedge pci_clk)
853
                pci_ad_reg <= get_next_data(3, pci_ad_reg) ;
854
        end
855
 
856
        pci_irdy_reg    <= 1'b0 ;
857
        pci_irdy_en_reg <= 1'b1 ;
858
        pci_trdy_reg    <= 1'b1 ;
859
 
860
        @(posedge pci_clk) ;
861
 
862
        // check for errors detected during the test
863
        check_master_errors(0) ;
864
 
865
        // now create an error during the simulated transfers - at first, second, one before last and last transfers
866
        current_error_offset = 1 ;
867
        while (current_error_offset <= i)
868
        begin
869
 
870
 
871
            num_of_transfers = 0 ;
872
            pci_ad_reg = get_first_data(2) ;
873
            configure_master_registers
874
            (
875
                0,          //transaction_size
876
                1,          //opcode
877
                0,          //base_address
878
                1,          //clear_transaction_counts
879
                1,          //initiate_test
880
                i,          //test size
881
                pci_ad_reg  //start_dat
882
            );
883
 
884
            @(posedge pci_clk) ;
885
 
886
            if ((num_of_transfers + 1) == current_error_offset)
887
            begin
888
                tmp = pci_ad_reg ;
889
                pci_ad_reg <= ~pci_ad_reg ;
890
            end
891
 
892
            pci_irdy_reg    <= 1'b0 ;
893
            pci_irdy_en_reg <= 1'b1 ;
894
            pci_trdy_reg    <= 1'b0 ;
895
 
896
            repeat(i)
897
            begin
898
                @(posedge pci_clk)
899
                begin
900
                    num_of_transfers = num_of_transfers + 1 ;
901
                    if (num_of_transfers == current_error_offset)
902
                    begin
903
                        pci_ad_reg <= get_next_data(2, tmp) ;
904
                    end
905
                    else if ((num_of_transfers + 1) == current_error_offset)
906
                    begin
907
                        tmp = pci_ad_reg ;
908
                        pci_ad_reg <= ~pci_ad_reg ;
909
                    end
910
                    else
911
                    begin
912
                        pci_ad_reg <= get_next_data(2, pci_ad_reg) ;
913
                    end
914
                end
915
            end
916
 
917
            pci_irdy_reg    <= 1'b0 ;
918
            pci_irdy_en_reg <= 1'b1 ;
919
            pci_trdy_reg    <= 1'b1 ;
920
 
921
            @(posedge pci_clk) ;
922
 
923
            // check for errors detected during the test
924
            check_master_errors(1) ;
925
 
926
            current_error_offset = current_error_offset * 2 ;
927
        end
928
    end
929
end
930
endtask // test_master_data_errors
931
 
932
function [31:0] get_next_data ;
933
    input [3:0]  pattern_select ;
934
    input [31:0] current_data ;
935
 
936
    reg [31:0] new_value ;
937
begin
938
    case (pattern_select)
939
        4'h0:
940
        begin
941
            new_value = current_data + 4 ;
942
        end
943
        4'h1:
944
        begin
945
            new_value = ~((~current_data) + 4) ;
946
        end
947
        4'h2, 4'h3:
948
        begin
949
            new_value = {current_data[30:0], current_data[31]} ;
950
        end
951
        4'h4:
952
        begin
953
            new_value     = current_data ;
954
            new_value[0]  = current_data[21] ^ current_data[5] ;
955
            new_value     = {new_value[30:0], new_value[31]} ;
956
        end
957
        default:
958
        begin
959
            new_value = 0 ;
960
        end
961
    endcase
962
 
963
    get_next_data = new_value ;
964
end
965
endfunction // get_next_data
966
 
967
function [31:0] get_first_data ;
968
    input [3:0] pattern_select ;
969
    reg [31:0] value ;
970
begin
971
    case (pattern_select)
972
        4'h0:
973
        begin
974
            value = 0 ;
975
        end
976
        4'h1:
977
        begin
978
            value = 32'hFFFF_FFFF ;
979
        end
980
        4'h2:
981
        begin
982
            value = 32'h0000_0001 ;
983
        end
984
        4'h3:
985
        begin
986
            value = 32'hFFFF_FFFE ;
987
        end
988
        4'h4:
989
        begin
990
            value = 32'hFFFF_FFFF ;
991
        end
992
        default:
993
        begin
994
            value = 0 ;
995
        end
996
    endcase
997
 
998
    get_first_data = value ;
999
end
1000
endfunction // get_first_data
1001
 
1002
task test_master_writes ;
1003
    integer i ;
1004
    integer j ;
1005
    reg [31:0] current_address ;
1006
    reg ok_wb ;
1007
    reg [3:0] pattern ;
1008
    reg [3:0] wait_states ;
1009
begin
1010
 
1011
    pattern = 0 ;
1012
    wait_states = 0 ;
1013
 
1014
    wb_master_waits = 0 ;
1015
 
1016
    for (j = 1 ; j <= 1024 ; j = j * 2)
1017
    begin
1018
 
1019
        current_address = j * 4 ;
1020
 
1021
        // configure registers to enable master writes
1022
        configure_master_registers(j, 1, current_address, 1'b0, 1'b0, 0, 0) ;
1023
 
1024
        // fill block rams with patterns
1025
        wbs_fill_with_bursts(pattern, j) ;
1026
 
1027
        // deactivate slave
1028
        wishbone_slave.cycle_response(0, 0, 0) ;
1029
 
1030
        fork
1031
        begin
1032
            // activate_master
1033
            activate_master('d1024 / j) ;
1034
 
1035
            // enable slave
1036
            wishbone_slave.cycle_response({1'b1, 1'b0, 1'b0}, wait_states, 0) ;
1037
        end
1038
        begin
1039
            for (i = 0 ; i < ('d1024 / j) ; i = i + 1)
1040
            begin
1041
                wb_transaction_progress_monitor
1042
                (
1043
                    current_address,    // address
1044
                    1'b1,               // write
1045
                    j,                  // num_of_transfers
1046
                    1'b1,               // check_transfers
1047
                    ok_wb               // ok
1048
                ) ;
1049
 
1050
                if (ok_wb !== 1'b1)
1051
                begin
1052
                    `TIME ;
1053
                    `ERROR("Transaction progress monitor detected invalid transaction!") ;
1054
                    $stop ;
1055
                end
1056
                current_address = current_address + (j * 4) ;
1057
            end
1058
        end
1059
        join
1060
 
1061
        // check the data
1062
        current_address = get_first_data(pattern) ;
1063
        for (i = 0 ; i < j ; i = i + 1)
1064
        begin
1065
            current_address = get_next_data(pattern, current_address) ;
1066
        end
1067
 
1068
        for (i = 0 ; i < 1024 ; i = i + 1)
1069
        begin
1070
            if ((i + j) == 1024)
1071
                current_address = get_first_data(pattern) ;
1072
 
1073
            if (wishbone_slave.wb_memory[i + j] !== current_address)
1074
            begin
1075
                `TIME ;
1076
                `ERROR("Test Master written wrong data value to the slave") ;
1077
                `VALUES(current_address, wishbone_slave.wb_memory[i]) ;
1078
                $stop ;
1079
            end
1080
 
1081
            current_address = get_next_data(pattern, current_address) ;
1082
        end
1083
 
1084
        pattern = pattern + 1 ;
1085
        if (pattern > 4)
1086
            pattern = 0 ;
1087
 
1088
        wait_states = wait_states + 1 ;
1089
        wb_master_waits = wb_master_waits + 1 ;
1090
    end
1091
 
1092
    wb_master_waits = 0 ;
1093
end
1094
endtask // test_master_writes
1095
 
1096
task test_master_reads ;
1097
    integer i ;
1098
    integer j ;
1099
    reg [31:0] current_address ;
1100
    reg ok_wb ;
1101
    reg [3:0] pattern ;
1102
    reg [3:0] wait_states ;
1103
begin
1104
 
1105
    pattern = 0 ;
1106
    wait_states = 0 ;
1107
 
1108
    wb_master_waits = 0 ;
1109
 
1110
    for (j = 1 ; j <= 1024 ; j = j * 2)
1111
    begin
1112
 
1113
        current_address = j * 4 ;
1114
 
1115
        // configure registers to enable master reads
1116
        configure_master_registers(j, 0, current_address, 1'b0, 1'b0, 0, 0) ;
1117
 
1118
        current_address = get_first_data(pattern) ;
1119
        for (i = 0 ; i < j ; i = i + 1)
1120
        begin
1121
            current_address = get_next_data(pattern, current_address) ;
1122
        end
1123
 
1124
        // fill slave memory with patterns
1125
        for (i = j ; i < (1024 + j) ; i = i + 1)
1126
        begin
1127
            if (i == 1024)
1128
                current_address = get_first_data(pattern) ;
1129
 
1130
            wishbone_slave.wb_memory[i] = current_address ;
1131
            current_address = get_next_data(pattern, current_address) ;
1132
        end
1133
 
1134
        // deactivate slave
1135
        wishbone_slave.cycle_response(0, 0, 0) ;
1136
 
1137
        current_address = j * 4 ;
1138
 
1139
        fork
1140
        begin
1141
            // activate_master
1142
            activate_master('d1024 / j) ;
1143
 
1144
            // enable slave
1145
            wishbone_slave.cycle_response({1'b1, 1'b0, 1'b0}, wait_states, 0) ;
1146
        end
1147
        begin
1148
            for (i = 0 ; i < ('d1024 / j) ; i = i + 1)
1149
            begin
1150
                wb_transaction_progress_monitor
1151
                (
1152
                    current_address,    // address
1153
                    1'b0,               // write
1154
                    j,                  // num_of_transfers
1155
                    1'b1,               // check_transfers
1156
                    ok_wb               // ok
1157
                ) ;
1158
 
1159
                if (ok_wb !== 1'b1)
1160
                begin
1161
                    `TIME ;
1162
                    `ERROR("Transaction progress monitor detected invalid transaction!") ;
1163
                    $stop ;
1164
                end
1165
                current_address = current_address + (j * 4) ;
1166
            end
1167
        end
1168
        join
1169
 
1170
        // check the data
1171
        wbs_check_data_with_bursts(pattern, j) ;
1172
 
1173
        pattern = pattern + 1 ;
1174
        if (pattern > 4)
1175
            pattern = 0 ;
1176
 
1177
        wait_states = wait_states + 1 ;
1178
        wb_master_waits = wb_master_waits + 1 ;
1179
    end
1180
 
1181
    wb_master_waits = 0 ;
1182
end
1183
endtask // test_master_reads
1184
 
1185
task configure_master_registers ;
1186
    input [10:0] transaction_size ;
1187
    input        opcode ;
1188
    input [31:0] base_address ;
1189
    input        clear_transaction_counts ;
1190
    input        initiate_test ;
1191
    input [20:0] test_size ;
1192
    input [31:0] start_dat ;
1193
begin
1194
    // write transaction size
1195
    wb_master_single_write(32'h0000_1000, {21'h1FFF_FF, transaction_size}) ;
1196
    wb_master_single_read (32'hFFFF_F000, {21'h0000_00, transaction_size}) ;
1197
 
1198
    // write opcode
1199
    wb_master_single_write(32'h0000_1008, {31'h7FFF_FFFF, opcode}) ;
1200
    wb_master_single_read (32'hFFFF_F008, {31'h0000_0000, opcode}) ;
1201
 
1202
    // write base address
1203
    wb_master_single_write(32'h0000_100C, base_address) ;
1204
    wb_master_single_read (32'hFFFF_F00C, {base_address[31:2], 2'b00}) ;
1205
 
1206
    // if clear of wb and pci transaction counters is requested clear them
1207
    if (clear_transaction_counts)
1208
    begin
1209
        wb_master_single_write(32'hFFFF_F024, 32'hFFFF_FFFF) ;
1210
        repeat(3)
1211
            @(posedge pci_clk) ;
1212
 
1213
        wb_master_single_read(32'h0000_1024, 32'h0) ;
1214
        wb_master_single_read(32'h0000_1028, 32'h0) ;
1215
    end
1216
 
1217
    if (initiate_test)
1218
    begin
1219
        wb_master_single_write(32'hFFFF_F030, start_dat) ;
1220
        wb_master_single_read(32'h0000_1030, start_dat) ;
1221
 
1222
        wb_master_single_write(32'hFFFF_F02C, {11'h0, test_size}) ;
1223
        wb_master_single_read(32'h0000_102C, {11'h0, test_size}) ;
1224
 
1225
        repeat(2)
1226
            @(posedge pci_clk) ;
1227
 
1228
        repeat(2)
1229
            @(posedge clk) ;
1230
 
1231
        // check the write - it should not be succesfull, since test is not done yet
1232
        wb_master_single_write(32'hFFFF_F02C, 0) ;
1233
 
1234
        wb_master_single_read(32'h0000_102C, {11'h0, test_size}) ;
1235
 
1236
        // all reported errors should be cleared by now!
1237
        wb_master_single_read(32'h0000_1034, 32'h0) ;
1238
    end
1239
end
1240
endtask // configure_master_registers
1241
 
1242
task configure_slave_registers ;
1243
    input [31:0] start_adr ;
1244
    input [31:0] start_dat ;
1245
    input [10:0] test_size ;
1246
    input        clear_burst_cnt ;
1247
    input        clear_errors ;
1248
begin
1249
    if (clear_burst_cnt)
1250
    begin
1251
        wb_master_single_write(32'h0000_1010, 32'hFFFF_FFFF) ;
1252
        wb_master_single_read (32'hFFFF_F010, 32'h0) ;
1253
    end
1254
 
1255
    if (clear_errors)
1256
    begin
1257
        wb_master_single_write(32'h0000_1020, 32'hFFFF_FFFF) ;
1258
        wb_master_single_read (32'hFFFF_F020, 32'h0        ) ;
1259
    end
1260
 
1261
 
1262
    wb_master_single_write(32'h0000_1018, start_adr) ;
1263
    wb_master_single_read (32'hFFFF_F018, start_adr) ;
1264
 
1265
    wb_master_single_write(32'h0000_101C, start_dat) ;
1266
    wb_master_single_read (32'hFFFF_F01C, start_dat) ;
1267
 
1268
    wb_master_single_write(32'h0000_1014, {21'h1F_FFFF, test_size}) ;
1269
    wb_master_single_read (32'hFFFF_F014, {21'h0, test_size}) ;
1270
 
1271
end
1272
endtask // configure_slave_registers
1273
 
1274
task check_slave_errors ;
1275
    input expect_adr_err ;
1276
    input expect_dat_err ;
1277
begin
1278
    wb_master_single_read (32'hFFFF_F020, {30'h0, expect_adr_err, expect_dat_err}) ;
1279
end
1280
endtask // check_slave_errors
1281
 
1282
task check_master_errors ;
1283
    input expect_dat_err ;
1284
begin
1285
    wb_master_single_read(32'h0000_1034, {31'h0, expect_dat_err}) ;
1286
end
1287
endtask // check_master_errors
1288
 
1289
task activate_master ;
1290
    input [10:0] num_of_transactions ;
1291
begin
1292
    wb_master_single_write(32'h0000_1004, {21'h1FFF_FF, num_of_transactions}) ;
1293
    wb_master_single_read (32'hFFFF_F004, {21'h0000_00, num_of_transactions}) ;
1294
end
1295
endtask // activate_master
1296
 
1297
reg wbm_cyc_o_previous ;
1298
 
1299
always@(posedge clk)
1300
    wbm_cyc_o_previous <= wbm_cyc_o ;
1301
 
1302
task wb_transaction_progress_monitor ;
1303
    input [31:0] address ;
1304
    input        write ;
1305
    input [31:0] num_of_transfers ;
1306
    input check_transfers ;
1307
    output ok ;
1308
    reg in_use ;
1309
    integer deadlock_counter ;
1310
    integer transfer_counter ;
1311
    integer deadlock_max_val ;
1312
    reg [2:0] slave_termination ;
1313
    reg       cab_asserted ;
1314
begin:main
1315
    if ( in_use === 1 )
1316
    begin
1317
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
1318
        ok = 0 ;
1319
        disable main ;
1320
    end
1321
 
1322
    // number of cycles on WB bus for maximum transaction length
1323
    deadlock_max_val = 50 ;
1324
 
1325
    in_use       = 1 ;
1326
    ok           = 1 ;
1327
    cab_asserted = 0 ;
1328
 
1329
    fork
1330
    begin:wait_start
1331
        deadlock_counter = 0 ;
1332
        @(posedge clk) ;
1333
        while ( (wbm_cyc_o !== 0 && wbm_cyc_o_previous !== 0) && (deadlock_counter < deadlock_max_val) )
1334
        begin
1335
                if ((!wbm_stb_o) || (!wbm_ack_i))
1336
                deadlock_counter = deadlock_counter + 1 ;
1337
            else
1338
                deadlock_counter = 0;
1339
            @(posedge clk) ;
1340
        end
1341
        if ( wbm_cyc_o !== 0 && wbm_cyc_o_previous !== 0)
1342
        begin
1343
            $display("wb_transaction_progress_monitor task waited for 50 cycles for previous transaction to complete! Time %t ", $time) ;
1344
            in_use = 0 ;
1345
            ok     = 0 ;
1346
            disable main ;
1347
        end
1348
 
1349
        deadlock_counter = 0 ;
1350
        while ( (wbm_cyc_o !== 1) && (deadlock_counter < deadlock_max_val) )
1351
        begin
1352
            deadlock_counter = deadlock_counter + 1 ;
1353
            @(posedge clk) ;
1354
        end
1355
 
1356
        if ( wbm_cyc_o !== 1 )
1357
        begin
1358
            $display("wb_transaction_progress_monitor task waited for 50 cycles for transaction to start! Time %t ", $time) ;
1359
            in_use = 0 ;
1360
            ok     = 0 ;
1361
            disable main ;
1362
        end
1363
    end //wait_start
1364
    begin:addr_monitor
1365
        @(posedge clk) ;
1366
        while ( wbm_cyc_o !== 0 && wbm_cyc_o_previous !== 0)
1367
            @(posedge clk) ;
1368
 
1369
        while( wbm_cyc_o !== 1 )
1370
            @(posedge clk) ;
1371
 
1372
        while (wbm_stb_o !== 1 )
1373
            @(posedge clk) ;
1374
 
1375
        if ( wbm_we_o !== write )
1376
        begin
1377
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
1378
            if ( write !== 1 )
1379
                $display("Expected read transaction, wbm_we_o signal value %b ", wbm_we_o) ;
1380
            else
1381
                $display("Expected write transaction, wbm_we_o signal value %b ", wbm_we_o) ;
1382
        end
1383
 
1384
        if ( wbm_adr_o !== address )
1385
        begin
1386
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
1387
            $display("Expected address = %h, detected address = %h ", address, wbm_adr_o) ;
1388
            ok = 0 ;
1389
        end
1390
    end
1391
    begin:transfer_checker
1392
        transfer_counter = 0 ;
1393
        @(posedge clk) ;
1394
        while ( wbm_cyc_o !== 0 && wbm_cyc_o_previous !== 0)
1395
            @(posedge clk) ;
1396
 
1397
        while( wbm_cyc_o !== 1 )
1398
            @(posedge clk) ;
1399
 
1400
        while( (wbm_cyc_o === 1) && (transfer_counter <= 1024) )
1401
        begin
1402
 
1403
            if (!cab_asserted)
1404
                cab_asserted = (wbm_cab_o !== 1'b0) ;
1405
 
1406
            if (wbm_stb_o === 1)
1407
            begin
1408
                slave_termination = {wbm_ack_i, wbm_err_i, wbm_rty_i} ;
1409
                if (wbm_ack_i)
1410
                    transfer_counter = transfer_counter + 1 ;
1411
            end
1412
            @(posedge clk) ;
1413
        end
1414
 
1415
        if (cab_asserted)
1416
        begin
1417
            // cab was sampled asserted
1418
            // if number of transfers was less than 2 - check for extraordinary terminations
1419
            if (transfer_counter < 2)
1420
            begin
1421
                // if cycle was terminated because of no response, error or retry, than it is OK to have CAB_O asserted while transfering 0 or 1 data.
1422
                // any other cases are wrong
1423
                case (slave_termination)
1424
                3'b000:begin end
1425
                3'b001:begin end
1426
                3'b010:begin end
1427
                default:begin
1428
                            ok = 0 ;
1429
                            $display("Time %t", $time) ;
1430
                            $display("WB_MASTER asserted CAB_O for single transfer") ;
1431
                        end
1432
                endcase
1433
            end
1434
        end
1435
        else
1436
        begin
1437
            // if cab is not asserted, then WB_MASTER should not read more than one data.
1438
            if (transfer_counter > 1)
1439
            begin
1440
                ok = 0 ;
1441
                $display("Time %t", $time) ;
1442
                $display("WB_MASTER didn't assert CAB_O for consecutive block transfer") ;
1443
            end
1444
        end
1445
 
1446
        if ( check_transfers === 1 )
1447
        begin
1448
            if ( transfer_counter !== num_of_transfers )
1449
            begin
1450
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
1451
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
1452
                ok = 0 ;
1453
            end
1454
        end
1455
    end //transfer_checker
1456
    join
1457
 
1458
    in_use = 0 ;
1459
end
1460
endtask // wb_transaction_progress_monitor
1461
 
1462
endmodule // test_bench

powered by: WebSVN 2.1.0

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