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

Subversion Repositories hssdrc

[/] [hssdrc/] [trunk/] [testbench/] [tb_prog.sv] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 des00
//
2
// Project      : High-Speed SDRAM Controller with adaptive bank management and command pipeline
3
//
4
// Project Nick : HSSDRC
5
//
6
// Version      : 1.0-beta
7
//
8
// Revision     : $Revision: 1.1 $
9
//
10
// Date         : $Date: 2008-03-06 13:54:00 $
11
//
12
// Workfile     : tb_prog.sv
13
//
14
// Description  : testbench program for all cases
15
//
16
// HSSDRC is licensed under MIT License
17
//
18
// Copyright (c) 2007-2008, Denis V.Shekhalev (des00@opencores.org)
19
//
20
// Permission  is hereby granted, free of charge, to any person obtaining a copy of
21
// this  software  and  associated documentation files (the "Software"), to deal in
22
// the  Software  without  restriction,  including without limitation the rights to
23
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
24
// the  Software, and to permit persons to whom the Software is furnished to do so,
25
// subject to the following conditions:
26
//
27
// The  above  copyright notice and this permission notice shall be included in all
28
// copies or substantial portions of the Software.
29
//
30
// THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
32
// FOR  A  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
33
// COPYRIGHT  HOLDERS  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
34
// IN  AN  ACTION  OF  CONTRACT,  TORT  OR  OTHERWISE,  ARISING  FROM, OUT OF OR IN
35
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
//
37
 
38
 
39
 
40
`include "hssdrc_timescale.vh"
41
`include "hssdrc_define.vh"
42
`include "hssdrc_timing.vh"
43
`include "tb_define.svh"
44
 
45
`include "message_class.sv"
46
 
47
`include "hssdrc_driver_class.sv"
48
`include "hssrdc_bandwidth_monitor_class.sv"
49
`include "hssrdc_scoreboard_class.sv"
50
 
51
`include "sdram_transaction_class.sv"
52
 
53
`include "sdram_tread_class.sv"
54
`include "sdram_agent_class.sv"
55
 
56
program tb_prog (interface sys_if);
57
 
58
  // agent <-> driver mailbox
59
  sdram_tr_mbx      agent2drv_mbx;
60
  sdram_tr_ack_mbx  drv2agent_mbx;
61
 
62
  // message service
63
  message_class msg;
64
 
65
  // test program -> agent mailbox
66
  sdram_tr_mbx agent_write_mbx;
67
  sdram_tr_mbx agent_read_mbx;
68
 
69
  // transaction agent class
70
  sdram_agent_class   agent;
71
 
72
  // virtual sdram treads
73
  sdram_tread_class   tread;
74
 
75
  // driver to uut
76
  hssrdc_driver_class             driver;
77
 
78
  // driver callbacks
79
  hssdrc_bandwidth_monitor_class  bandwidth_mon;
80
  hssdrc_scoreboard_class         scoreboard;
81
 
82
  event scoreboard_event;
83
  event bandwidth_mon_event;
84
 
85
  initial begin
86
 
87
    agent2drv_mbx     = new (8);
88
    drv2agent_mbx     = new (8);
89
 
90
    agent_write_mbx   = new (8);
91
    agent_read_mbx    = new (8);
92
 
93
    // init objects
94
    msg           = new ("tb_hssdrc.log");
95
 
96
    driver        = new (sys_if, agent2drv_mbx, drv2agent_mbx);
97
 
98
    agent         = new (agent2drv_mbx, drv2agent_mbx, agent_write_mbx, agent_read_mbx);
99
 
100
    tread         = new ;
101
 
102
    bandwidth_mon = new (sys_if, bandwidth_mon_event);
103
 
104
    scoreboard    = new (msg, scoreboard_event);
105
 
106
    driver.run();
107
 
108
    agent.run_write_read ();
109
 
110
    // calibrate bandwidth monitor
111
 
112
    bandwidth_mon.count_mbps_mfactor(1000);
113
 
114
    // disable debug process inside sdram model
115
 
116
    force tb_top.sdram_chip.Debug = 0;
117
 
118
    wait (sys_if.reset == 1'b0);
119
 
120
    wait (sys_if.cb.ready == 1'b1);
121
 
122
    msg.note ("Program start");
123
 
124
`ifdef HSSDRC_NOT_SHARE_ACT_COMMAND
125
    msg.note ("Controller use HSSDRC_NOT_SHARE_ACT_COMMAND macros");
126
`endif
127
 
128
`ifdef HSSDRC_SHARE_ONE_DECODER
129
    msg.note ("Controller use HSSDRC_SHARE_ONE_DECODER macros");
130
`endif
131
 
132
`ifdef HSSDRC_SHARE_NONE_DECODER
133
    msg.note ("Controller use HSSDRC_SHARE_NONE_DECODER macros");
134
`endif
135
 
136
    //test(-1,-1); // simple_debug_test
137
    //test(0,0);   // linear_test
138
    test(1,1);   // random_test
139
    //test(2,2);   // bandwidth_measurement
140
 
141
    agent.stop_write_read();
142
 
143
    driver.stop();
144
 
145
    msg.stop();
146
 
147
    $stop;
148
    $finish (2);
149
 
150
  end
151
 
152
  //
153
  //
154
  //
155
 
156
  task test (input int start_task, end_task);
157
    int task_num;
158
 
159
    sdram_transaction_class write_tr;
160
    sdram_transaction_class read_tr;
161
 
162
    sdram_transaction_class rand_tr;
163
    sdram_transaction_class tr;
164
 
165
    int err;
166
 
167
    int         tr_burst;
168
    tr_type_e_t tr_type;
169
    int         tr_id;
170
    int         tr_chid;
171
    int         tr_num;
172
 
173
    bit tread_end;
174
    int next_cola;
175
 
176
    sdram_tread_state_s_t tread_state;  // selected tread state
177
    int                   tread_num;    // selected tread num
178
 
179
    string log_str;
180
  begin
181
 
182
    for (task_num = start_task; task_num <= end_task; task_num++)
183
    begin
184
      //
185
      // Task -1 : manualy checking write/read transactions
186
      //
187
      if (task_num == -1) begin : simple_debug_test
188
 
189
        msg.note ($psprintf("test %0d : simple debug test", task_num));
190
 
191
        //
192
        // test for debug only
193
        //
194
 
195
        tr = new (0, cTR_WRITE_LOCKED, .ba(0), .rowa(0), .cola(0), .burst(3));
196
        tr.GetLinearPacket();
197
        agent.SetTransaction(tr);
198
 
199
        tr = new (0, cTR_WRITE_LOCKED, .ba(0), .rowa(0), .cola(0), .burst(4));
200
        tr.GetLinearPacket();
201
        agent.SetTransaction(tr);
202
 
203
        tr = new (0, cTR_READ_LOCKED, .ba(0), .rowa(0), .cola(0), .burst(4), .chid(1));
204
        tr.GetLinearPacket();
205
        agent.SetTransaction(tr);
206
 
207
//      tr = new (0, cTR_READ, .ba(0), .rowa(1), .cola(0), .burst(2));
208
//      tr.GetLinearPacket();
209
//      agent.SetTransaction(tr);
210
 
211
        tr = new (0, cTR_REFR_LOCKED, .ba(0), .rowa(0));
212
        agent.SetTransaction(tr);
213
 
214
        repeat (10) @(sys_if.cb);
215
      end : simple_debug_test
216
 
217
      //
218
      // Task 0 : linear write -> read with linear data (random burst only)
219
      //
220
 
221
      else if (task_num == 0) begin : linear_test
222
 
223
        msg.note ($psprintf("test %0d : linear write -> read with linear data", task_num));
224
 
225
        //
226
        // test for correctness. set scoreboard callbacks
227
        //
228
 
229
        driver.cbs = {};
230
        scoreboard.start();
231
        driver.cbs.push_back(scoreboard);
232
 
233
        driver.random_delay_mode = 1;
234
        //
235
        // transaction generator
236
        //
237
 
238
        tread.Init();
239
 
240
        msg.note ($psprintf("test %0d start_task with number of treads is %0d", task_num, tread.active_tread_state.num()));
241
 
242
        for (tread_num = 0; tread_num < tread.active_tread_state.num(); tread_num++) begin
243
 
244
          //
245
          // get tread state
246
          //
247
 
248
          tread_state = tread.active_tread_state [tread_num];
249
 
250
          msg.note ($psprintf("start tread %0d" , tread_num));
251
 
252
          //
253
          // full tread transaction
254
          //
255
 
256
          tr_num = 0;
257
 
258
          do begin
259
            //
260
            // generate transaction
261
            //
262
            tr_id     = tread_num;
263
            tr_type   = cTR_WRITE;
264
            tr_burst  = tread.GetBurst (tread_state);
265
            tr_chid   = tread_state.ba;
266
 
267
            write_tr = new (tr_id, tr_type, tread_state.ba, tread_state.rowa, tread_state.cola, tr_burst, tr_chid);
268
            write_tr.GetLinearPacket();
269
 
270
            read_tr = new write_tr;
271
            read_tr.tr_type = cTR_READ;
272
            //
273
            // set transaction
274
            //
275
            #10;
276
            agent_write_mbx.put (write_tr);
277
            #10;
278
            agent_read_mbx.put  (read_tr);
279
            //
280
            // update tread state
281
            //
282
            tr_num++;
283
 
284
            next_cola = tread_state.cola + tr_burst;
285
 
286
            tread_end = (next_cola >= cColaMaxValue);
287
 
288
            tread_state.cola = next_cola;
289
 
290
          end
291
          while (tread_end != 1);
292
 
293
          msg.note ($psprintf("done tread %0d. number of tread transactions %0d", tread_num, tr_num));
294
 
295
        end
296
 
297
        //
298
        // wait compare done
299
        //
300
 
301
        do
302
          @(scoreboard_event);
303
        while (agent.read_tr_done_num != scoreboard.checked_tr_num);
304
 
305
        msg.note ($psprintf("test%0d done. Number of errors = %0d", task_num, scoreboard.check_err_num));
306
 
307
      end : linear_test
308
 
309
      //
310
      // Task 1 : random write -> read with random data, rowa, ba, burst, linear cola
311
      //
312
 
313
      else if (task_num == 1) begin : random_test
314
 
315
        msg.note ($psprintf("test %0d : random write -> read with random data", task_num));
316
 
317
        //
318
        // test for correctness. set scoreboard callbacks
319
        //
320
 
321
        driver.cbs = {};
322
        scoreboard.start();
323
        driver.cbs.push_back(scoreboard);
324
 
325
        driver.random_delay_mode = 1;
326
 
327
        //
328
        // transaction generator
329
        //
330
 
331
        tread.Init();
332
 
333
        msg.note ($psprintf("test %0d start_task with number of treads is %0d", task_num, tread.active_tread_state.num()));
334
 
335
        tr_num = 0;
336
 
337
        do begin
338
 
339
          //
340
          // select tread
341
          //
342
 
343
          assert (tread.randomize()) else $error ("generate tread selection error");
344
 
345
          tread_num   = tread.curr_tread_num;
346
 
347
          tread_state = tread.active_tread_state [tread_num];
348
 
349
          //
350
          // generate transaction
351
          //
352
 
353
          tr_burst  = tread.GetBurst (tread_state);
354
          tr_type   = cTR_WRITE;
355
          tr_id     = tread_num;
356
          tr_chid   = tread_state.ba;
357
 
358
          write_tr = new (tr_id, tr_type, tread_state.ba, tread_state.rowa, tread_state.cola, tr_burst, tr_chid);
359
          //write_tr.GetLinearPacket();
360
          write_tr.GetRandomPacket();
361
 
362
          read_tr = new write_tr;
363
          read_tr.tr_type = cTR_READ;
364
          //
365
          // set transaction
366
          //
367
          #10;
368
          agent_write_mbx.put (write_tr);
369
          #10;
370
          agent_read_mbx.put  (read_tr);
371
          //
372
          // update tread state
373
          //
374
          tr_num++;
375
 
376
          next_cola = tread_state.cola + tr_burst;
377
 
378
          tread_end = (next_cola >= cColaMaxValue);
379
 
380
          tread_state.cola = next_cola;
381
 
382
          tread.active_tread_state [tread_num] = tread_state;
383
          //
384
          // if tread end kill it
385
          //
386
          if (tread_end) begin
387
            tread.active_tread_state.delete   (tread_num);
388
            tread.disable_tread_num.push_back (tread_num);  // random pointer constrain update
389
            msg.note ($psprintf("done tread %0d", tread_num));
390
          end
391
 
392
          if (tr_num > cTransactionMaxValue) break;
393
 
394
          if (tr_num % cTransactionLogPeriod == 0)
395
            msg.note($psprintf("transaction done %0d", tr_num));
396
 
397
        end
398
        while (tread.active_tread_state.num() != 0);
399
 
400
        //
401
        // wait compare done
402
        //
403
 
404
        do
405
          @(scoreboard_event);
406
        while (agent.read_tr_done_num != scoreboard.checked_tr_num);
407
 
408
        msg.note ($psprintf("test%0d done. Number of errors = %0d", task_num, scoreboard.check_err_num));
409
 
410
      end : random_test
411
 
412
      //
413
      // Task 2 : bandwidth measurement
414
      //
415
 
416
      else if (task_num == 2) begin : bandwidth_measurement
417
 
418
        msg.note ($psprintf("test %0d : access bandwidth measurement", task_num));
419
 
420
        //
421
        // test for perfromance. set bandwidth monitor callbacks, no random delay mode
422
        //
423
 
424
        driver.cbs = {};
425
        driver.cbs.push_back(bandwidth_mon);
426
 
427
        driver.random_delay_mode = 0;
428
 
429
        //
430
        // generate transactions
431
        //
432
        foreach ( test_mode [t] ) begin : test_mode_cycle
433
 
434
          msg.note ($psprintf("test %0d start %0s test mode", task_num, test_mode_name[test_mode[t]]));
435
 
436
          foreach (burst_mode [b]) begin : burst_cycle
437
 
438
            foreach (address_mode [a] ) begin : address_cycle
439
 
440
              time start_time;
441
              string str;
442
 
443
              tr_num = 0;
444
              start_time = $time;
445
 
446
              //
447
              // init tr.generator
448
              //
449
 
450
              rand_tr = new;
451
              rand_tr.burst_random_mode   = burst_mode [b];
452
              rand_tr.address_random_mode = address_mode [a];
453
 
454
              bandwidth_mon.start();
455
 
456
              do begin
457
 
458
                assert ( rand_tr.randomize() ) else begin
459
                  $error("test %0d : random transaction generate error", task_num);
460
                  $stop;
461
                end
462
 
463
                if ( test_mode[t].write_mode) begin
464
                  write_tr          = new rand_tr;
465
                  write_tr.id       = tr_num++;
466
                  write_tr.tr_type  = cTR_WRITE;
467
 
468
                  agent.SetTransaction(write_tr);
469
                end
470
 
471
                if ( test_mode[t].read_mode) begin
472
                  read_tr         = new rand_tr;
473
                  read_tr.id      = tr_num++;
474
                  read_tr.tr_type = cTR_READ;
475
 
476
                  agent.SetTransaction(read_tr);
477
                end
478
 
479
                if (tr_num % cTransactionLogPeriod == 0)
480
                  msg.note($psprintf("task %0d transaction done %0d", task_num, tr_num));
481
 
482
              end
483
              while (($time - start_time) < cPerfomanceInterval);
484
 
485
              //
486
              // syncronize output for measure
487
              //
488
              do
489
                @(bandwidth_mon_event);
490
              while (tr_num != bandwidth_mon.measured_tr_num);
491
 
492
              //
493
              // stop measure
494
              //
495
              bandwidth_mon.stop();
496
 
497
              //
498
              // logs
499
              //
500
 
501
              str = $psprintf("task %0d done. %0s mode bandwith : %0s and %0s is :\n", task_num,
502
                test_mode_name[test_mode[t]], address_mode_name [address_mode[a]], burst_mode_name [burst_mode[b]]);
503
 
504
              if (test_mode [t].write_mode)
505
                str = {str, $psprintf("\t\twrite bandwidth %0f MBps, %0f %% maximum ram bandwidth\n",
506
                  bandwidth_mon.write_bandwidth, bandwidth_mon.write_bandwidth_percent)};
507
 
508
              if (test_mode [t].read_mode)
509
                str = {str, $psprintf("\t\t read bandwidth %0f MBps, %0f %% maximum ram bandwidth\n",
510
                  bandwidth_mon.read_bandwidth, bandwidth_mon.read_bandwidth_percent)};
511
 
512
              if (test_mode [t].read_mode & test_mode [t].write_mode)
513
                str = {str, $psprintf("\t\tram bandwidth %0f MBps, %0f %% maximum ram bandwidth\n",
514
                  bandwidth_mon.bandwidth, bandwidth_mon.bandwidth_percent)};
515
 
516
              msg.note(str);
517
 
518
            end : address_cycle
519
 
520
          end : burst_cycle
521
 
522
        end : test_mode_cycle
523
 
524
 
525
      end : bandwidth_measurement
526
 
527
    end
528
 
529
    msg.note ("all test done");
530
 
531
    repeat (100) @(sys_if.cb);
532
  end
533
 
534
  endtask
535
 
536
 
537
 
538
endprogram

powered by: WebSVN 2.1.0

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