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

Subversion Repositories xgate

[/] [xgate/] [trunk/] [bench/] [verilog/] [tst_bench_top.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  WISHBONE revB.2 compliant Xgate Coprocessor - Test Bench
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/xgate.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2009, Robert Hayes
12
//
13
// This source file is free software: you can redistribute it and/or modify
14
// it under the terms of the GNU Lesser General Public License as published
15
// by the Free Software Foundation, either version 3 of the License, or
16
// (at your option) any later version.
17
//
18
// Supplemental terms.
19
//     * Redistributions of source code must retain the above copyright
20
//       notice, this list of conditions and the following disclaimer.
21
//     * Neither the name of the <organization> nor the
22
//       names of its contributors may be used to endorse or promote products
23
//       derived from this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
29
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
//
36
// You should have received a copy of the GNU General Public License
37
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
38
////////////////////////////////////////////////////////////////////////////////
39
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
40
 
41
 
42
`include "timescale.v"
43
 
44
module tst_bench_top();
45
 
46
  parameter MAX_CHANNEL = 127;    // Max XGATE Interrupt Channel Number
47 5 rehayes
  parameter STOP_ON_ERROR = 1'b0;
48 2 rehayes
 
49
  //
50
  // wires && regs
51
  //
52
  reg        mstr_test_clk;
53
  reg [19:0] vector;
54
  reg [ 7:0] test_num;
55
  reg [15:0] wb_temp;
56
  reg        rstn;
57
  reg        sync_reset;
58
  reg        por_reset_b;
59
  reg        stop_mode;
60
  reg        wait_mode;
61
  reg        debug_mode;
62
  reg        scantestmode;
63 5 rehayes
 
64
  reg       wbm_ack_i;
65 2 rehayes
 
66
 
67
  wire [31:0] adr;
68
  wire [15:0] dat_i, dat_o, dat0_i, dat1_i, dat2_i, dat3_i;
69
  wire we;
70
  wire stb;
71
  wire cyc;
72
  wire ack, ack_1, ack_2, ack_3, ack_4;
73
  wire inta_1, inta_2, inta_3, inta_4;
74
  wire count_en_1;
75
  wire count_flag_1;
76
 
77
  reg [15:0] q, qq;
78
 
79
  reg  [  7:0] ram_8 [65535:0];
80
  wire         write_mem_strb_l;
81
  wire         write_mem_strb_h;
82
  reg  [127:0] channel_req;
83
  wire [  7:0] xgswt;        // XGATE Software Triggers
84
  wire [MAX_CHANNEL:0] xgif; // Max XGATE Interrupt Channel Number
85
 
86
 
87
  wire [15:0] xgate_address;
88
  wire [15:0] write_mem_data;
89
  wire [15:0] read_mem_data;
90 5 rehayes
 
91
  wire [15:0] wbm_dat_o;
92
  wire [15:0] wbm_dat_i;
93
  wire [15:0] wbm_adr_o;
94
  wire [ 1:0] wbm_sel_o;
95 2 rehayes
 
96
  wire scl, scl0_o, scl0_oen, scl1_o, scl1_oen;
97
  wire sda, sda0_o, sda0_oen, sda1_o, sda1_oen;
98
 
99
  // Name Address Locations
100
  parameter XGATE_XGMCTL   = 5'h00;
101
  parameter XGATE_XGCHID   = 5'h01;
102
  parameter XGATE_XGISPHI  = 5'h02;
103
  parameter XGATE_XGISPLO  = 5'h03;
104
  parameter XGATE_XGVBR    = 5'h04;
105
  parameter XGATE_XGIF_7   = 5'h05;
106
  parameter XGATE_XGIF_6   = 5'h06;
107
  parameter XGATE_XGIF_5   = 5'h07;
108
  parameter XGATE_XGIF_4   = 5'h08;
109
  parameter XGATE_XGIF_3   = 5'h09;
110
  parameter XGATE_XGIF_2   = 5'h0a;
111
  parameter XGATE_XGIF_1   = 5'h0b;
112
  parameter XGATE_XGIF_0   = 5'h0c;
113
  parameter XGATE_XGSWT    = 5'h0d;
114
  parameter XGATE_XGSEM    = 5'h0e;
115
  parameter XGATE_RES1     = 5'h0f;
116
  parameter XGATE_XGCCR    = 5'h10;
117
  parameter XGATE_XGPC     = 5'h11;
118
  parameter XGATE_RES1     = 5'h12;
119
  parameter XGATE_XGR1     = 5'h13;
120
  parameter XGATE_XGR2     = 5'h14;
121
  parameter XGATE_XGR3     = 5'h15;
122
  parameter XGATE_XGR4     = 5'h16;
123
  parameter XGATE_XGR5     = 5'h17;
124
  parameter XGATE_XGR6     = 5'h18;
125
  parameter XGATE_XGR7     = 5'h19;
126
 
127
  parameter COP_CNTRL = 5'b0_0000;
128
 
129
  parameter COP_CNTRL_COP_EVENT  = 16'h0100;  // COP Enable interrupt request
130
 
131 5 rehayes
  parameter CHECK_POINT = 16'h8000;
132
  parameter CHANNEL_ACK = CHECK_POINT + 2;
133
  parameter CHANNEL_ERR = CHECK_POINT + 4;
134
  reg [ 7:0] check_point_reg;
135
  reg [ 7:0] channel_ack_reg;
136
  reg [ 7:0] channel_err_reg;
137
  event check_point_wrt;
138
  event channel_ack_wrt;
139
  event channel_err_wrt;
140
  reg [15:0] error_count;
141 2 rehayes
 
142
  // initial values and testbench setup
143
  initial
144
    begin
145
      mstr_test_clk = 0;
146
      vector = 0;
147
      test_num = 0;
148
      por_reset_b = 0;
149
      stop_mode = 0;
150
      wait_mode = 0;
151
      debug_mode = 0;
152
      scantestmode = 0;
153 5 rehayes
      check_point_reg = 0;
154
      channel_ack_reg = 0;
155
      channel_err_reg = 0;
156
      error_count = 0;
157
      wbm_ack_i = 0;
158 2 rehayes
      // channel_req = 0;
159
 
160
      `ifdef WAVES
161
           $shm_open("waves");
162
           $shm_probe("AS",tst_bench_top,"AS");
163
           $display("\nINFO: Signal dump enabled ...\n\n");
164
      `endif
165
 
166
      `ifdef WAVES_V
167
           $dumpfile ("xgate_wave_dump.lxt");
168
           $dumpvars (0, tst_bench_top);
169
           $dumpon;
170
           $display("\nINFO: VCD Signal dump enabled ...\n\n");
171
      `endif
172
 
173
    end
174
 
175
  // generate clock
176
  always #20 mstr_test_clk = ~mstr_test_clk;
177
 
178 5 rehayes
  // Keep a count of how many clocks we've simulated
179 2 rehayes
  always @(posedge mstr_test_clk)
180 5 rehayes
    vector <= vector + 1;
181 2 rehayes
 
182 5 rehayes
  // Throw in some wait states from the memory
183
  always @(posedge mstr_test_clk)
184
//    if (((vector % 7) == 0) && (xgate.risc.cpu_state == 4'b0001))
185
//    if (((vector % 5) == 0) && (xgate.risc.load_next_inst))
186
    if ((vector % 5) == 0)
187
      wbm_ack_i <= 1'b0;
188
    else
189
      wbm_ack_i <= 1'b1;
190 2 rehayes
 
191
  // Write memory interface to RAM
192
  always @(posedge mstr_test_clk)
193
    begin
194 5 rehayes
      if (write_mem_strb_l && !write_mem_strb_h && wbm_ack_i)
195
        ram_8[xgate_address] <= write_mem_data[7:0];
196
      if (write_mem_strb_h && !write_mem_strb_l && wbm_ack_i)
197
        ram_8[xgate_address] <= write_mem_data[7:0];
198
      if (write_mem_strb_h && write_mem_strb_l && wbm_ack_i)
199 2 rehayes
        begin
200 5 rehayes
          ram_8[xgate_address]   <= write_mem_data[15:8];
201
          ram_8[xgate_address+1] <= write_mem_data[7:0];
202 2 rehayes
        end
203
    end
204
 
205
  // Special Memory Mapped Testbench Registers
206
  always @(posedge mstr_test_clk or negedge rstn)
207
    begin
208
      if (!rstn)
209
        begin
210 5 rehayes
          check_point_reg <= 0;
211
          channel_ack_reg <= 0;
212
          channel_err_reg <= 0;
213 2 rehayes
        end
214 5 rehayes
      if (write_mem_strb_l && wbm_ack_i && (xgate_address == CHECK_POINT))
215
        begin
216
          check_point_reg <= write_mem_data[7:0];
217
          -> check_point_wrt;
218
        end
219
      if (write_mem_strb_l && wbm_ack_i && (xgate_address == CHANNEL_ACK))
220
        begin
221
          channel_ack_reg <= write_mem_data[7:0];
222
          -> channel_ack_wrt;
223
        end
224
      if (write_mem_strb_l && wbm_ack_i && (xgate_address == CHANNEL_ERR))
225
        begin
226
          channel_err_reg <= write_mem_data[7:0];
227
          -> channel_err_wrt;
228
        end
229 2 rehayes
    end
230
 
231 5 rehayes
  always @check_point_wrt
232 2 rehayes
    $display("\nSoftware Checkpoint #%d -- at vector=%d\n", check_point_reg, vector);
233
 
234 5 rehayes
  always @channel_err_wrt
235
    begin
236
      $display("\n ------ !!!!! Software Error #%d -- at vector=%d\n  -------", channel_err_reg, vector);
237
      error_count = error_count + 1;
238
      if (STOP_ON_ERROR == 1'b1)
239
        wrap_up;
240
    end
241
 
242 2 rehayes
  wire [ 6:0] current_active_channel = xgate.risc.xgchid;
243 5 rehayes
  always @channel_ack_wrt
244 2 rehayes
    clear_channel(current_active_channel);
245
 
246
 
247
  // hookup wishbone master model
248
  wb_master_model #(.dwidth(16), .awidth(32))
249
          u0 (
250
          .clk(mstr_test_clk),
251
          .rst(rstn),
252
          .adr(adr),
253
          .din(dat_i),
254
          .dout(dat_o),
255
          .cyc(cyc),
256
          .stb(stb),
257
          .we(we),
258
          .sel(),
259
          .ack(ack),
260
          .err(1'b0),
261
          .rty(1'b0)
262
  );
263
 
264
 
265
  // Address decoding for different XGATE module instances
266
  wire stb0 = stb && ~adr[6] && ~adr[5];
267
  wire stb1 = stb && ~adr[6] &&  adr[5];
268
  wire stb2 = stb &&  adr[6] && ~adr[5];
269
  wire stb3 = stb &&  adr[6] &&  adr[5];
270
 
271
  assign dat1_i = 16'h0000;
272
  assign dat2_i = 16'h0000;
273
  assign dat3_i = 16'h0000;
274
  assign ack_2 = 1'b0;
275
  assign ack_3 = 1'b0;
276
  assign ack_4 = 1'b0;
277
 
278
  // Create the Read Data Bus
279
  assign dat_i = ({16{stb0}} & dat0_i) |
280
                 ({16{stb1}} & dat1_i) |
281
                 ({16{stb2}} & dat2_i) |
282
                 ({16{stb3}} & {8'b0, dat3_i[7:0]});
283
 
284
  assign ack = ack_1 || ack_2 || ack_3 || ack_4;
285
 
286
  assign read_mem_data = {ram_8[xgate_address], ram_8[xgate_address+1]};
287
 
288 5 rehayes
  // hookup XGATE core - Parameters take all default values
289 2 rehayes
  //  Async Reset, 16 bit Bus, 16 bit Granularity
290
  xgate_top  #(.SINGLE_CYCLE(1'b0),
291
               .MAX_CHANNEL(MAX_CHANNEL))    // Max XGATE Interrupt Channel Number
292
          xgate(
293 5 rehayes
          // Wishbone slave interface
294
          .wbs_clk_i( mstr_test_clk ),
295
          .wbs_rst_i( 1'b0 ),         // sync_reset
296
          .arst_i( rstn ),            // async resetn
297
          .wbs_adr_i( adr[4:0] ),
298
          .wbs_dat_i( dat_o ),
299
          .wbs_dat_o( dat0_i ),
300
          .wbs_we_i( we ),
301
          .wbs_stb_i( stb0 ),
302
          .wbs_cyc_i( cyc ),
303 2 rehayes
          .wbs_sel_i( 2'b11 ),
304 5 rehayes
          .wbs_ack_o( ack_1 ),
305 2 rehayes
 
306 5 rehayes
          // Wishbone master Signals
307
          .wbm_dat_o( write_mem_data ),
308
          .wbm_we_o( wbm_we_o ),
309
          .wbm_stb_o( wbm_stb_o ),
310
          .wbm_cyc_o( wbm_cyc_o ),
311
          .wbm_sel_o( wbm_sel_o ),
312
          .wbm_adr_o( xgate_address ),
313
          .wbm_dat_i( read_mem_data ),
314
          .wbm_ack_i( wbm_ack_i ),
315
 
316 2 rehayes
          .xgif( xgif ),             // XGATE Interrupt Flag
317
          .risc_clk( mstr_test_clk ),
318 5 rehayes
          .xgswt( xgswt ),
319 2 rehayes
          .chan_req_i( {channel_req[127:40], xgswt, channel_req[31:0]} ),
320
          .write_mem_strb_l( write_mem_strb_l ),
321
          .write_mem_strb_h( write_mem_strb_h ),
322
          .scantestmode( scantestmode )
323
  );
324
 
325
 
326
 
327
////////////////////////////////////////////////////////////////////////////////
328
////////////////////////////////////////////////////////////////////////////////
329
////////////////////////////////////////////////////////////////////////////////
330
 
331
// Test Program
332
initial
333
  begin
334
      $readmemh("../../../bench/verilog/jump_mem.v", ram_8);
335
      $display("\nstatus at time: %t Testbench started", $time);
336
 
337
      // reset system
338
      rstn = 1'b1; // negate reset
339
      channel_req = 1; // 
340
      repeat(1) @(posedge mstr_test_clk);
341
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
342
      #2;          // move the async reset away from the clock edge
343
      rstn = 1'b0; // assert async reset
344
      #5;          // Keep the async reset pulse with less than a clock cycle
345
      rstn = 1'b1; // negate async reset
346
      por_reset_b = 1'b1;
347
      channel_req = 0; // 
348
      repeat(1) @(posedge mstr_test_clk);
349
      sync_reset = 1'b0;
350
      channel_req = 0; // 
351
 
352
      $display("\nstatus at time: %t done reset", $time);
353
      test_num = test_num + 1;
354
 
355
 
356
      activate_thread_sw(1);
357
      wait_irq_set(1);
358
      u0.wb_write(1, XGATE_XGIF_0, 16'h0002);
359
 
360
      activate_thread_sw(2);
361
      wait_irq_set(2);
362
      u0.wb_write(1, XGATE_XGIF_0, 16'h0004);
363
 
364
      activate_thread_sw(3);
365
      wait_irq_set(3);
366
      u0.wb_write(1, XGATE_XGIF_0, 16'h0008);
367
 
368
      activate_thread_sw(4);
369
      wait_irq_set(4);
370
      u0.wb_write(1, XGATE_XGIF_0, 16'h0010);
371
 
372
      activate_thread_sw(5);
373
      wait_irq_set(5);
374
      u0.wb_write(1, XGATE_XGIF_0, 16'h0020);
375
 
376
      activate_thread_sw(6);
377
      wait_irq_set(6);
378
      u0.wb_write(1, XGATE_XGIF_0, 16'h0040);
379
 
380
      activate_thread_sw(7);
381
      wait_irq_set(7);
382
      u0.wb_write(1, XGATE_XGIF_0, 16'h0080);
383
 
384
      activate_thread_sw(8);
385
      wait_irq_set(8);
386
      u0.wb_write(1, XGATE_XGIF_0, 16'h0100);
387
 
388
      activate_thread_sw(9);
389
      wait_irq_set(9);
390
      u0.wb_write(1, XGATE_XGIF_0, 16'h0200);
391
 
392
      u0.wb_write(1, XGATE_XGSEM, 16'h5050);
393
      u0.wb_cmp(0, XGATE_XGSEM,    16'h0050);   //
394
      activate_thread_sw(10);
395
      wait_irq_set(10);
396
      u0.wb_write(1, XGATE_XGIF_0, 16'h0400);
397
      u0.wb_write(1, XGATE_XGSEM, 16'hff00);    // clear the old settings
398
      u0.wb_cmp(0, XGATE_XGSEM,    16'h0000);   //
399
      u0.wb_write(1, XGATE_XGSEM, 16'ha0a0);    // Verify that bits were unlocked by RISC
400
      u0.wb_cmp(0, XGATE_XGSEM,    16'h00a0);   // Verify bits were set
401
      u0.wb_write(1, XGATE_XGSEM, 16'hff08);    // Try to set the bit that was left locked by the RISC
402
      u0.wb_cmp(0, XGATE_XGSEM,    16'h0000);   // Verify no bits were set
403
 
404
      repeat(2) @(posedge mstr_test_clk);
405
 
406
      activate_channel(33);
407
      repeat(20) @(posedge mstr_test_clk);
408
      activate_channel(20);
409
      repeat(20) @(posedge mstr_test_clk);
410
 
411
      dump_ram(0);
412 5 rehayes
      wrap_up;
413 2 rehayes
      //
414
      // program core
415
      //
416
 
417
      reg_test_16;
418
 
419
      repeat(10) @(posedge mstr_test_clk);
420
 
421 5 rehayes
      wrap_up;
422 2 rehayes
  end
423
 
424
// Poll for XGATE Interrupt set
425
task wait_irq_set;
426
  input [ 6:0] chan_val;
427
  begin
428
    while(!xgif[chan_val])
429
      @(posedge mstr_test_clk); // poll it until it is set
430
    $display("XGATE Interrupt Request set detected at vector =%d", vector);
431
  end
432
endtask
433
 
434
// Poll for flag set
435
task wait_flag_set;
436
  begin
437
    u0.wb_read(1, COP_CNTRL, q);
438
    while(~|(q & COP_CNTRL_COP_EVENT))
439
      u0.wb_read(1, COP_CNTRL, q); // poll it until it is set
440
    $display("COP Flag set detected at vector =%d", vector);
441
  end
442
endtask
443
 
444
// check register bits - reset, read/write
445
task reg_test_16;
446
  begin
447
      test_num = test_num + 1;
448
      $display("TEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
449
      u0.wb_cmp(0, XGATE_XGMCTL,   16'h0000);   // verify reset
450
      u0.wb_cmp(0, XGATE_XGCHID,   16'h0000);   // verify reset
451
      u0.wb_cmp(0, XGATE_XGISPHI,  16'h0000);   // verify reset
452
      u0.wb_cmp(0, XGATE_XGISPLO,  16'h0000);   // verify reset
453
      u0.wb_cmp(0, XGATE_XGVBR,    16'h0000);   // verify reset
454
      u0.wb_cmp(0, XGATE_XGIF_7,   16'h0000);   // verify reset
455
      u0.wb_cmp(0, XGATE_XGIF_6,   16'h0000);   // verify reset
456
      u0.wb_cmp(0, XGATE_XGIF_5,   16'h0000);   // verify reset
457
      u0.wb_cmp(0, XGATE_XGIF_4,   16'h0000);   // verify reset
458
      u0.wb_cmp(0, XGATE_XGIF_3,   16'h0000);   // verify reset
459
      u0.wb_cmp(0, XGATE_XGIF_2,   16'h0000);   // verify reset
460
      u0.wb_cmp(0, XGATE_XGIF_1,   16'h0000);   // verify reset
461
      u0.wb_cmp(0, XGATE_XGIF_0,   16'h0000);   // verify reset
462
      u0.wb_cmp(0, XGATE_XGSWT,    16'h0000);   // verify reset
463
      u0.wb_cmp(0, XGATE_XGSEM,    16'h0000);   // verify reset
464
      u0.wb_cmp(0, XGATE_XGCCR,    16'h0000);   // verify reset
465
      u0.wb_cmp(0, XGATE_XGPC,     16'h0000);   // verify reset
466
      u0.wb_cmp(0, XGATE_XGR1,     16'h0000);   // verify reset
467
      u0.wb_cmp(0, XGATE_XGR2,     16'h0000);   // verify reset
468
      u0.wb_cmp(0, XGATE_XGR3,     16'h0000);   // verify reset
469
      u0.wb_cmp(0, XGATE_XGR4,     16'h0000);   // verify reset
470
      u0.wb_cmp(0, XGATE_XGR5,     16'h0000);   // verify reset
471
      u0.wb_cmp(0, XGATE_XGR6,     16'h0000);   // verify reset
472
      u0.wb_cmp(0, XGATE_XGR7,     16'h0000);   // verify reset
473
 
474
      u0.wb_write(1, XGATE_XGR1, 16'h5555);
475
      u0.wb_cmp(  0, XGATE_XGR1, 16'h5555);
476
      u0.wb_write(1, XGATE_XGR2, 16'haaaa);
477
      u0.wb_cmp(  0, XGATE_XGR2, 16'haaaa);
478
      u0.wb_write(1, XGATE_XGR3, 16'h9999);
479
      u0.wb_cmp(  0, XGATE_XGR3, 16'h9999);
480
      u0.wb_write(1, XGATE_XGR4, 16'hcccc);
481
      u0.wb_cmp(  0, XGATE_XGR4, 16'hcccc);
482
      u0.wb_write(1, XGATE_XGR5, 16'h3333);
483
      u0.wb_cmp(  0, XGATE_XGR5, 16'h3333);
484
      u0.wb_write(1, XGATE_XGR6, 16'h6666);
485
      u0.wb_cmp(  0, XGATE_XGR6, 16'h6666);
486
      u0.wb_write(1, XGATE_XGR7, 16'ha5a5);
487
      u0.wb_cmp(  0, XGATE_XGR7, 16'ha5a5);
488
 
489
      u0.wb_write(1, XGATE_XGPC, 16'h5a5a);
490
      u0.wb_cmp(  0, XGATE_XGPC, 16'h5a5a);
491
 
492
      u0.wb_write(1, XGATE_XGCCR, 16'hfffa);
493
      u0.wb_cmp(  0, XGATE_XGCCR, 16'h000a);
494
      u0.wb_write(1, XGATE_XGCCR, 16'hfff5);
495
      u0.wb_cmp(  0, XGATE_XGCCR, 16'h0005);
496
 
497
  end
498
endtask
499
 
500
 
501
 
502
 
503
task system_reset;  // reset system
504
  begin
505
      repeat(1) @(posedge mstr_test_clk);
506
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
507
      #2;                 // move the async reset away from the clock edge
508
      rstn = 1'b0;        // assert async reset
509
      #5;                 // Keep the async reset pulse with less than a clock cycle
510
      rstn = 1'b1;        // negate async reset
511
      repeat(1) @(posedge mstr_test_clk);
512
      sync_reset = 1'b0;
513
 
514
      $display("\nstatus: %t System Reset Task Done", $time);
515
      test_num = test_num + 1;
516
 
517
      repeat(2) @(posedge mstr_test_clk);
518
   end
519
endtask
520
 
521
 
522
task activate_channel;
523
  input [ 6:0] chan_val;
524
  begin
525
      $display("Activating Channel %d", chan_val);
526
 
527
      channel_req[chan_val] = 1'b1; // 
528
      repeat(1) @(posedge mstr_test_clk);
529
  end
530
endtask
531
 
532
 
533
task clear_channel;
534
  input [ 6:0] chan_val;
535
  begin
536
      $display("Clearing Channel interrupt input #%d", chan_val);
537
 
538
      channel_req[chan_val] = 1'b0; // 
539
      repeat(1) @(posedge mstr_test_clk);
540
   end
541
endtask
542
 
543
 
544
task clear_irq_flag;
545
  input [ 6:0] chan_val;
546
  begin
547
      $display("Clearing Channel interrupt flag #%d", chan_val);
548
      if (0 < chan_val < 16)
549
        u0.wb_write(1, XGATE_XGIF_0, 16'hffff);
550
      if (15 < chan_val < 32)
551
        u0.wb_write(1, XGATE_XGIF_1, 16'hffff);
552
      if (31 < chan_val < 48)
553
        u0.wb_write(1, XGATE_XGIF_2, 16'hffff);
554
      if (47 < chan_val < 64)
555
        u0.wb_write(1, XGATE_XGIF_3, 16'hffff);
556
      if (63 < chan_val < 80)
557
        u0.wb_write(1, XGATE_XGIF_4, 16'hffff);
558
      if (79 < chan_val < 96)
559
        u0.wb_write(1, XGATE_XGIF_5, 16'hffff);
560
      if (95 < chan_val < 112)
561
        u0.wb_write(1, XGATE_XGIF_6, 16'hffff);
562
      if (111 < chan_val < 128)
563
        u0.wb_write(1, XGATE_XGIF_7, 16'hffff);
564
 
565
      channel_req[chan_val] = 1'b0; // 
566
      repeat(1) @(posedge mstr_test_clk);
567
   end
568
endtask
569
 
570
 
571
task activate_thread_sw;
572
  input [ 6:0] chan_val;
573
  begin
574
      $display("Activating Sofrware Thread - Channel #%d", chan_val);
575
 
576
      u0.wb_write(0, XGATE_XGMCTL,   16'h8080);   // Enable XGATE
577
 
578
      channel_req[chan_val] = 1'b1; // 
579
      repeat(1) @(posedge mstr_test_clk);
580
   end
581
endtask
582
 
583
task dump_ram;
584
  input [15:0] start_address;
585
  reg   [15:0] dump_address;
586
  integer i, j;
587
  begin
588
      $display("Dumping RAM - Starting Address #%h", start_address);
589
 
590
      dump_address = start_address;
591
      while (dump_address <= start_address + 16'h0080)
592
        begin
593
          $write("Address = %h", dump_address);
594
          for (i = 0; i < 16; i = i + 1)
595
            begin
596
              $write(" %h", ram_8[dump_address]);
597
              dump_address = dump_address + 1;
598
            end
599
        $write("\n");
600
        end
601
 
602
  end
603
endtask
604
 
605 5 rehayes
task wrap_up;
606
  begin
607
    $display("\nSimulation Finished!! - vector =%d", vector);
608
    if (error_count == 0)
609
      $display("Simulation Passed");
610
    else
611
      $display("Simulation Failed");
612
 
613
    $finish;
614
  end
615
endtask
616
 
617 2 rehayes
function [15:0] four_2_16;
618
  input [3:0] vector;
619
  begin
620
    case (vector)
621
      4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
622
      4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
623
      4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
624
      4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
625
      4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
626
      4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
627
      4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
628
      4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
629
      4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
630
      4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
631
      4'ha : four_2_16 = 16'b0000_0100_0000_0000;
632
      4'hb : four_2_16 = 16'b0000_1000_0000_0000;
633
      4'hc : four_2_16 = 16'b0001_0000_0000_0000;
634
      4'hd : four_2_16 = 16'b0010_0000_0000_0000;
635
      4'he : four_2_16 = 16'b0100_0000_0000_0000;
636
      4'hf : four_2_16 = 16'b1000_0000_0000_0000;
637
    endcase
638
  end
639
endfunction
640
 
641
endmodule  // tst_bench_top
642
 

powered by: WebSVN 2.1.0

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