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

Subversion Repositories xgate

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

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 21 rehayes
  parameter MAX_VECTOR = 2100;
49
 
50 2 rehayes
  //
51
  // wires && regs
52
  //
53
  reg        mstr_test_clk;
54
  reg [19:0] vector;
55
  reg [ 7:0] test_num;
56
  reg [15:0] wb_temp;
57
  reg        rstn;
58
  reg        sync_reset;
59
  reg        por_reset_b;
60
  reg        stop_mode;
61
  reg        wait_mode;
62
  reg        debug_mode;
63
  reg        scantestmode;
64 21 rehayes
 
65 5 rehayes
  reg       wbm_ack_i;
66 2 rehayes
 
67
 
68
  wire [31:0] adr;
69
  wire [15:0] dat_i, dat_o, dat0_i, dat1_i, dat2_i, dat3_i;
70
  wire we;
71
  wire stb;
72
  wire cyc;
73
  wire ack, ack_1, ack_2, ack_3, ack_4;
74
  wire inta_1, inta_2, inta_3, inta_4;
75
  wire count_en_1;
76
  wire count_flag_1;
77
 
78
  reg [15:0] q, qq;
79 21 rehayes
 
80
  reg  [  7:0] ram_8 [65535:0];      // Testbench memory for holding XGATE test code
81 2 rehayes
  wire         write_mem_strb_l;
82
  wire         write_mem_strb_h;
83 21 rehayes
  reg  [MAX_CHANNEL:0] channel_req;  // XGATE Interrupt inputs
84
  wire [MAX_CHANNEL:0] xgif;         // XGATE Interrupt outputs
85
  wire         [  7:0] xgswt;        // XGATE Software Trigger outputs
86
  wire                 xg_sw_irq;    // Xgate Software Error interrupt
87 2 rehayes
 
88
 
89 21 rehayes
  wire [15:0] wbm_dat_o;         // WISHBONE Master Mode data output from XGATE
90
  wire [15:0] wbm_dat_i;         // WISHBONE Master Mode data input to XGATE
91
  wire [15:0] wbm_adr_o;         // WISHBONE Master Mode address output from XGATE
92 5 rehayes
  wire [ 1:0] wbm_sel_o;
93 2 rehayes
 
94
 
95
  // Name Address Locations
96
  parameter XGATE_XGMCTL   = 5'h00;
97
  parameter XGATE_XGCHID   = 5'h01;
98
  parameter XGATE_XGISPHI  = 5'h02;
99
  parameter XGATE_XGISPLO  = 5'h03;
100
  parameter XGATE_XGVBR    = 5'h04;
101
  parameter XGATE_XGIF_7   = 5'h05;
102
  parameter XGATE_XGIF_6   = 5'h06;
103
  parameter XGATE_XGIF_5   = 5'h07;
104
  parameter XGATE_XGIF_4   = 5'h08;
105
  parameter XGATE_XGIF_3   = 5'h09;
106
  parameter XGATE_XGIF_2   = 5'h0a;
107
  parameter XGATE_XGIF_1   = 5'h0b;
108
  parameter XGATE_XGIF_0   = 5'h0c;
109
  parameter XGATE_XGSWT    = 5'h0d;
110
  parameter XGATE_XGSEM    = 5'h0e;
111
  parameter XGATE_RES1     = 5'h0f;
112
  parameter XGATE_XGCCR    = 5'h10;
113
  parameter XGATE_XGPC     = 5'h11;
114 21 rehayes
  parameter XGATE_RES2     = 5'h12;
115 2 rehayes
  parameter XGATE_XGR1     = 5'h13;
116
  parameter XGATE_XGR2     = 5'h14;
117
  parameter XGATE_XGR3     = 5'h15;
118
  parameter XGATE_XGR4     = 5'h16;
119
  parameter XGATE_XGR5     = 5'h17;
120
  parameter XGATE_XGR6     = 5'h18;
121
  parameter XGATE_XGR7     = 5'h19;
122 21 rehayes
 
123 11 rehayes
  // Define bits in XGATE Control Register
124
  parameter XGMCTL_XGEM     = 16'h8000;
125
  parameter XGMCTL_XGFRZM   = 16'h4000;
126
  parameter XGMCTL_XGDBGM   = 15'h2000;
127
  parameter XGMCTL_XGSSM    = 15'h1000;
128
  parameter XGMCTL_XGFACTM  = 15'h0800;
129
  parameter XGMCTL_XGBRKIEM = 15'h0400;
130
  parameter XGMCTL_XGSWEIFM = 15'h0200;
131
  parameter XGMCTL_XGIEM    = 15'h0100;
132
  parameter XGMCTL_XGE      = 16'h0080;
133
  parameter XGMCTL_XGFRZ    = 16'h0040;
134
  parameter XGMCTL_XGDBG    = 15'h0020;
135
  parameter XGMCTL_XGSS     = 15'h0010;
136
  parameter XGMCTL_XGFACT   = 15'h0008;
137
  parameter XGMCTL_XGBRKIE  = 15'h0004;
138
  parameter XGMCTL_XGSWEIF  = 15'h0002;
139
  parameter XGMCTL_XGIE     = 15'h0001;
140 2 rehayes
 
141
 
142 5 rehayes
  parameter CHECK_POINT = 16'h8000;
143
  parameter CHANNEL_ACK = CHECK_POINT + 2;
144
  parameter CHANNEL_ERR = CHECK_POINT + 4;
145
  reg [ 7:0] check_point_reg;
146
  reg [ 7:0] channel_ack_reg;
147
  reg [ 7:0] channel_err_reg;
148
  event check_point_wrt;
149
  event channel_ack_wrt;
150
  event channel_err_wrt;
151
  reg [15:0] error_count;
152 21 rehayes
 
153 11 rehayes
  reg        mem_wait_state_enable;
154 21 rehayes
 
155 11 rehayes
  // Registers used to mirror internal registers
156
  reg [15:0] data_xgmctl;
157
  reg [15:0] data_xgchid;
158
  reg [15:0] data_xgvbr;
159
  reg [15:0] data_xgswt;
160
  reg [15:0] data_xgsem;
161 2 rehayes
 
162
  // initial values and testbench setup
163
  initial
164
    begin
165
      mstr_test_clk = 0;
166
      vector = 0;
167
      test_num = 0;
168
      por_reset_b = 0;
169
      stop_mode = 0;
170
      wait_mode = 0;
171
      debug_mode = 0;
172
      scantestmode = 0;
173 5 rehayes
      check_point_reg = 0;
174
      channel_ack_reg = 0;
175
      channel_err_reg = 0;
176
      error_count = 0;
177 11 rehayes
      wbm_ack_i = 1;
178
      mem_wait_state_enable = 0;
179 2 rehayes
      // channel_req = 0;
180
 
181
      `ifdef WAVES
182
           $shm_open("waves");
183
           $shm_probe("AS",tst_bench_top,"AS");
184
           $display("\nINFO: Signal dump enabled ...\n\n");
185
      `endif
186
 
187
      `ifdef WAVES_V
188
           $dumpfile ("xgate_wave_dump.lxt");
189
           $dumpvars (0, tst_bench_top);
190
           $dumpon;
191
           $display("\nINFO: VCD Signal dump enabled ...\n\n");
192
      `endif
193
 
194
    end
195
 
196
  // generate clock
197
  always #20 mstr_test_clk = ~mstr_test_clk;
198
 
199 5 rehayes
  // Keep a count of how many clocks we've simulated
200 2 rehayes
  always @(posedge mstr_test_clk)
201 11 rehayes
    begin
202
      vector <= vector + 1;
203
      if (vector > MAX_VECTOR)
204 21 rehayes
        begin
205
          error_count <= error_count + 1;
206
          $display("\n ------ !!!!! Simulation Timeout at vector=%d\n -------", vector);
207
          wrap_up;
208
        end
209 11 rehayes
    end
210 2 rehayes
 
211 21 rehayes
  // Add up errors tha come from WISHBONE read compares
212
  always @u0.cmp_error_detect
213
    begin
214
      error_count <= error_count + 1;
215
    end
216 11 rehayes
 
217 21 rehayes
 
218 5 rehayes
  // Throw in some wait states from the memory
219
  always @(posedge mstr_test_clk)
220 11 rehayes
    if (((vector % 5) == 0) && (xgate.risc.load_next_inst || xgate.risc.data_access))
221
//    if ((vector % 5) == 0)
222 5 rehayes
      wbm_ack_i <= 1'b0;
223 21 rehayes
    else
224 5 rehayes
      wbm_ack_i <= 1'b1;
225 2 rehayes
 
226 11 rehayes
 
227 2 rehayes
  // Write memory interface to RAM
228
  always @(posedge mstr_test_clk)
229
    begin
230 5 rehayes
      if (write_mem_strb_l && !write_mem_strb_h && wbm_ack_i)
231 21 rehayes
        ram_8[wbm_adr_o] <= wbm_dat_o[7:0];
232 5 rehayes
      if (write_mem_strb_h && !write_mem_strb_l && wbm_ack_i)
233 21 rehayes
        ram_8[wbm_adr_o] <= wbm_dat_o[7:0];
234 5 rehayes
      if (write_mem_strb_h && write_mem_strb_l && wbm_ack_i)
235 21 rehayes
        begin
236
          ram_8[wbm_adr_o]   <= wbm_dat_o[15:8];
237
          ram_8[wbm_adr_o+1] <= wbm_dat_o[7:0];
238
        end
239 2 rehayes
    end
240
 
241
  // Special Memory Mapped Testbench Registers
242
  always @(posedge mstr_test_clk or negedge rstn)
243
    begin
244
      if (!rstn)
245 21 rehayes
        begin
246
          check_point_reg <= 0;
247
          channel_ack_reg <= 0;
248
          channel_err_reg <= 0;
249
        end
250
      if (write_mem_strb_l && wbm_ack_i && (wbm_adr_o == CHECK_POINT))
251
        begin
252
          check_point_reg <= wbm_dat_o[7:0];
253
          #1;
254
          -> check_point_wrt;
255
        end
256
      if (write_mem_strb_l && wbm_ack_i && (wbm_adr_o == CHANNEL_ACK))
257
        begin
258
          channel_ack_reg <= wbm_dat_o[7:0];
259
          #1;
260
          -> channel_ack_wrt;
261
        end
262
      if (write_mem_strb_l && wbm_ack_i && (wbm_adr_o == CHANNEL_ERR))
263
        begin
264
          channel_err_reg <= wbm_dat_o[7:0];
265
          #1;
266
          -> channel_err_wrt;
267
        end
268 2 rehayes
    end
269
 
270 5 rehayes
  always @check_point_wrt
271 11 rehayes
    $display("\nSoftware Checkpoint #%h -- at vector=%d\n", check_point_reg, vector);
272 2 rehayes
 
273 5 rehayes
  always @channel_err_wrt
274
    begin
275
      $display("\n ------ !!!!! Software Error #%d -- at vector=%d\n  -------", channel_err_reg, vector);
276
      error_count = error_count + 1;
277
      if (STOP_ON_ERROR == 1'b1)
278 21 rehayes
        wrap_up;
279 5 rehayes
    end
280
 
281 2 rehayes
  wire [ 6:0] current_active_channel = xgate.risc.xgchid;
282 5 rehayes
  always @channel_ack_wrt
283 2 rehayes
    clear_channel(current_active_channel);
284 21 rehayes
 
285
 
286 2 rehayes
  // hookup wishbone master model
287
  wb_master_model #(.dwidth(16), .awidth(32))
288
          u0 (
289 21 rehayes
          // Outputs
290 2 rehayes
          .cyc(cyc),
291
          .stb(stb),
292
          .we(we),
293
          .sel(),
294 21 rehayes
          .adr(adr),
295
          .dout(dat_o),
296
          // inputs
297
          .din(dat_i),
298
          .clk(mstr_test_clk),
299 2 rehayes
          .ack(ack),
300 21 rehayes
          .rst(rstn),
301 2 rehayes
          .err(1'b0),
302
          .rty(1'b0)
303
  );
304
 
305
 
306
  // Address decoding for different XGATE module instances
307
  wire stb0 = stb && ~adr[6] && ~adr[5];
308
  wire stb1 = stb && ~adr[6] &&  adr[5];
309
  wire stb2 = stb &&  adr[6] && ~adr[5];
310
  wire stb3 = stb &&  adr[6] &&  adr[5];
311
 
312
  assign dat1_i = 16'h0000;
313
  assign dat2_i = 16'h0000;
314
  assign dat3_i = 16'h0000;
315
  assign ack_2 = 1'b0;
316
  assign ack_3 = 1'b0;
317
  assign ack_4 = 1'b0;
318
 
319
  // Create the Read Data Bus
320
  assign dat_i = ({16{stb0}} & dat0_i) |
321
                 ({16{stb1}} & dat1_i) |
322
                 ({16{stb2}} & dat2_i) |
323
                 ({16{stb3}} & {8'b0, dat3_i[7:0]});
324 21 rehayes
 
325 2 rehayes
  assign ack = ack_1 || ack_2 || ack_3 || ack_4;
326
 
327 21 rehayes
  assign wbm_dat_i = {ram_8[wbm_adr_o], ram_8[wbm_adr_o+1]};
328
 
329 5 rehayes
  // hookup XGATE core - Parameters take all default values
330 2 rehayes
  //  Async Reset, 16 bit Bus, 16 bit Granularity
331 11 rehayes
  xgate_top  #(.SINGLE_CYCLE(1'b1),
332 21 rehayes
               .MAX_CHANNEL(MAX_CHANNEL))    // Max XGATE Interrupt Channel Number
333 2 rehayes
          xgate(
334 5 rehayes
          // Wishbone slave interface
335
          .wbs_clk_i( mstr_test_clk ),
336
          .wbs_rst_i( 1'b0 ),         // sync_reset
337
          .arst_i( rstn ),            // async resetn
338
          .wbs_adr_i( adr[4:0] ),
339
          .wbs_dat_i( dat_o ),
340
          .wbs_dat_o( dat0_i ),
341
          .wbs_we_i( we ),
342
          .wbs_stb_i( stb0 ),
343
          .wbs_cyc_i( cyc ),
344 2 rehayes
          .wbs_sel_i( 2'b11 ),
345 5 rehayes
          .wbs_ack_o( ack_1 ),
346 2 rehayes
 
347 5 rehayes
          // Wishbone master Signals
348 21 rehayes
          .wbm_dat_o( wbm_dat_o ),
349 5 rehayes
          .wbm_we_o( wbm_we_o ),
350
          .wbm_stb_o( wbm_stb_o ),
351
          .wbm_cyc_o( wbm_cyc_o ),
352
          .wbm_sel_o( wbm_sel_o ),
353 21 rehayes
          .wbm_adr_o( wbm_adr_o ),
354
          .wbm_dat_i( wbm_dat_i ),
355 5 rehayes
          .wbm_ack_i( wbm_ack_i ),
356
 
357 21 rehayes
          .xgif( xgif ),             // XGATE Interrupt Flag output
358
          .xg_sw_irq( xg_sw_irq ),   // XGATE Software Error Interrupt Flag output
359
          .xgswt( xgswt ),
360 2 rehayes
          .risc_clk( mstr_test_clk ),
361 21 rehayes
          .chan_req_i( {channel_req[MAX_CHANNEL:40], xgswt, channel_req[31:0]} ),
362
          .write_mem_strb_l( write_mem_strb_l ),
363
          .write_mem_strb_h( write_mem_strb_h ),
364 2 rehayes
          .scantestmode( scantestmode )
365
  );
366
 
367
 
368
 
369
////////////////////////////////////////////////////////////////////////////////
370
////////////////////////////////////////////////////////////////////////////////
371
////////////////////////////////////////////////////////////////////////////////
372
 
373
// Test Program
374
initial
375
  begin
376
      $display("\nstatus at time: %t Testbench started", $time);
377
 
378
      // reset system
379
      rstn = 1'b1; // negate reset
380 21 rehayes
      channel_req = 1; //
381 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
382
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
383
      #2;          // move the async reset away from the clock edge
384
      rstn = 1'b0; // assert async reset
385
      #5;          // Keep the async reset pulse with less than a clock cycle
386
      rstn = 1'b1; // negate async reset
387
      por_reset_b = 1'b1;
388 21 rehayes
      channel_req = 0; //
389 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
390
      sync_reset = 1'b0;
391 21 rehayes
      channel_req = 0; //
392 2 rehayes
 
393
      $display("\nstatus at time: %t done reset", $time);
394 21 rehayes
 
395 11 rehayes
      test_inst_set;
396 21 rehayes
 
397 11 rehayes
      test_debug_mode;
398 2 rehayes
 
399 21 rehayes
      test_debug_bit;
400
 
401
      test_chid_debug;
402
 
403 5 rehayes
      wrap_up;
404 2 rehayes
      //
405
      // program core
406
      //
407
 
408
      reg_test_16;
409 21 rehayes
 
410 2 rehayes
      repeat(10) @(posedge mstr_test_clk);
411
 
412 5 rehayes
      wrap_up;
413 2 rehayes
  end
414
 
415 21 rehayes
// Test CHID Debug mode operation
416
task test_chid_debug;
417
  begin
418
    test_num = test_num + 1;
419
    $display("\nTEST #%d Starts at vector=%d, test_chid_debug", test_num, vector);
420
    $readmemh("../../../bench/verilog/debug_test.v", ram_8);
421
 
422
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
423
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Enable interrupt on BRK instruction
424
 
425
    activate_thread_sw(3);
426
 
427
    wait_debug_set;   // Debug Status bit is set by BRK instruction
428
 
429
    u0.wb_cmp(0, XGATE_XGPC,     16'h20c6);      // See Program code (BRK).
430
    u0.wb_cmp(0, XGATE_XGR3,     16'h0001);      // See Program code.R3 = 1
431
    u0.wb_cmp(0, XGATE_XGCHID,   16'h0003);      // Check for Correct CHID
432
 
433
    channel_req[5] = 1'b1; //
434
    repeat(7) @(posedge mstr_test_clk);
435
    u0.wb_cmp(0, XGATE_XGCHID,   16'h0003);      // Check for Correct CHID
436
 
437
    u0.wb_write(0, XGATE_XGCHID, 16'h000f);      // Change CHID
438
    u0.wb_cmp(0, XGATE_XGCHID,   16'h000f);      // Check for Correct CHID
439
 
440
    u0.wb_write(0, XGATE_XGCHID, 16'h0000);      // Change CHID to 00, RISC should go to IDLE state
441
 
442
    repeat(1) @(posedge mstr_test_clk);
443
 
444
    u0.wb_write(0, XGATE_XGCHID, 16'h0004);      // Change CHID
445
 
446
    repeat(8) @(posedge mstr_test_clk);
447
 
448
    data_xgmctl = XGMCTL_XGDBGM;
449
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Debug Mode Control Bit
450
 
451
    wait_debug_set;   // Debug Status bit is set by BRK instruction
452
    u0.wb_cmp(0, XGATE_XGCHID,   16'h0004);      // Check for Correct CHID
453
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Debug Mode Control Bit (Excape from Break State and run)
454
 
455
    wait_debug_set;   // Debug Status bit is set by BRK instruction
456
    u0.wb_cmp(0, XGATE_XGCHID,   16'h0005);      // Check for Correct CHID
457
    activate_channel(6);
458
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Debug Mode Control Bit (Excape from Break State and run)
459
 
460
    wait_debug_set;   // Debug Status bit is set by BRK instruction
461
    u0.wb_cmp(0, XGATE_XGCHID,   16'h0006);      // Check for Correct CHID
462
    u0.wb_cmp(0, XGATE_XGPC,     16'h211c);      // See Program code (BRK)
463
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
464
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step
465
    repeat(8) @(posedge mstr_test_clk);
466
    u0.wb_cmp(0, XGATE_XGPC,     16'h211e);      // See Program code (BRA)
467
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step
468
    repeat(8) @(posedge mstr_test_clk);
469
    u0.wb_cmp(0, XGATE_XGPC,     16'h2122);      // See Program code ()
470
 
471
    repeat(20) @(posedge mstr_test_clk);
472
 
473
    data_xgmctl = XGMCTL_XGDBGM;
474
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Debug Mode Control Bit
475
 
476
    repeat(50) @(posedge mstr_test_clk);
477
 
478
  end
479
endtask
480
 
481 11 rehayes
// Test Debug bit operation
482
task test_debug_bit;
483 2 rehayes
  begin
484 11 rehayes
    test_num = test_num + 1;
485 21 rehayes
    $display("\nTEST #%d Starts at vector=%d, test_debug_bit", test_num, vector);
486 11 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", ram_8);
487 21 rehayes
 
488 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
489
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Enable interrupt on BRK instruction
490
 
491
    activate_thread_sw(2);
492 21 rehayes
 
493 11 rehayes
    repeat(25) @(posedge mstr_test_clk);
494
 
495
    data_xgmctl = XGMCTL_XGDBGM | XGMCTL_XGDBG;
496
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Set Debug Mode Control Bit
497 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
498
 
499
    u0.wb_read(1, XGATE_XGR3, q);
500
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
501
    qq = q;
502
 
503
    // The Xgate test program is in an infinate loop incrementing R3
504
    while (qq == q)  // Look for change in R3 register
505
      begin
506
        u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step
507
        repeat(5) @(posedge mstr_test_clk);
508
        u0.wb_read(1, XGATE_XGR3, q);
509
      end
510
    if (q != (qq+1))
511
      begin
512
        $display("Error! - Unexpected value of R3 at vector=%d", vector);
513
        error_count = error_count + 1;
514
      end
515
 
516
 
517
    u0.wb_write(1, XGATE_XGPC, 16'h2094);        // Write to PC to force exit from infinate loop
518
    repeat(5) @(posedge mstr_test_clk);
519
 
520
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
521
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (Load ADDL instruction)
522
    repeat(5) @(posedge mstr_test_clk);
523
    u0.wb_cmp(0, XGATE_XGR4,     16'h0002);      // See Program code.(R4 <= R4 + 1)
524
 
525
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (Load ADDL instruction)
526
    repeat(5) @(posedge mstr_test_clk);
527
    u0.wb_cmp(0, XGATE_XGR4,     16'h0003);      // See Program code.(R4 <= R4 + 1)
528
 
529
    data_xgmctl = XGMCTL_XGDBGM;
530
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Debug Mode Control Bit
531 11 rehayes
                                                 // Should be back in Run Mode
532 21 rehayes
 
533
//    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
534
//    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Software Interrupt and BRK Interrupt Enable Bit
535 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
536 21 rehayes
 
537 2 rehayes
  end
538
endtask
539
 
540 11 rehayes
// Test Debug mode operation
541
task test_debug_mode;
542 2 rehayes
  begin
543 11 rehayes
    test_num = test_num + 1;
544
    $display("\nTEST #%d Starts at vector=%d, test_debug_mode", test_num, vector);
545
    $readmemh("../../../bench/verilog/debug_test.v", ram_8);
546 21 rehayes
 
547 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
548
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Enable interrupt on BRK instruction
549
 
550
    activate_thread_sw(1);
551 21 rehayes
 
552 11 rehayes
    wait_debug_set;   // Debug Status bit is set by BRK instruction
553
 
554
    u0.wb_cmp(0, XGATE_XGPC,     16'h203a);      // See Program code (BRK).
555
    u0.wb_cmp(0, XGATE_XGR3,     16'h0001);      // See Program code.R3 = 1
556
 
557
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
558
 
559
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (Load ADDL instruction)
560
    repeat(5) @(posedge mstr_test_clk);
561
    u0.wb_cmp(0, XGATE_XGPC,     16'h203c);      // PC + 2.
562
 
563
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (Load NOP instruction)
564
    repeat(5) @(posedge mstr_test_clk);          // Execute ADDL instruction
565
    u0.wb_cmp(0, XGATE_XGR3,     16'h0002);      // See Program code.(R3 <= R3 + 1)
566
    u0.wb_cmp(0, XGATE_XGCCR,    16'h0000);      // See Program code.
567
    u0.wb_cmp(0, XGATE_XGPC,     16'h203e);      // PC + 2.
568
    repeat(5) @(posedge mstr_test_clk);
569
    u0.wb_cmp(0, XGATE_XGPC,     16'h203e);      // Still no change.
570
 
571
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (Load BRA instruction)
572
    repeat(9) @(posedge mstr_test_clk);          // Execute NOP instruction
573
    u0.wb_cmp(0, XGATE_XGPC,     16'h2040);      // See Program code.
574
 
575
 
576
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step
577
    repeat(5) @(posedge mstr_test_clk);          // Execute BRA instruction
578
    u0.wb_cmp(0, XGATE_XGPC,     16'h2064);      // PC = Branch destination.
579
                                                 // Load ADDL instruction
580 21 rehayes
 
581 11 rehayes
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (Load LDW R7 instruction)
582
    repeat(5) @(posedge mstr_test_clk);          // Execute ADDL instruction
583
    u0.wb_cmp(0, XGATE_XGPC,     16'h2066);      // PC + 2.
584
    u0.wb_cmp(0, XGATE_XGR3,     16'h0003);      // See Program code.(R3 <= R3 + 1)
585
 
586
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (LDW R7)
587
    repeat(5) @(posedge mstr_test_clk);
588
    u0.wb_cmp(0, XGATE_XGPC,     16'h2068);      // PC + 2.
589
    u0.wb_cmp(0, XGATE_XGR7,     16'h00c3);      // See Program code
590
 
591
    repeat(1) @(posedge mstr_test_clk);
592
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (BRA)
593
    repeat(9) @(posedge mstr_test_clk);
594
    u0.wb_cmp(0, XGATE_XGPC,     16'h2048);      // See Program code.
595
 
596
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (STW R3)
597
    repeat(5) @(posedge mstr_test_clk);
598
    u0.wb_cmp(0, XGATE_XGPC,     16'h204a);      // PC + 2.
599
    u0.wb_cmp(0, XGATE_XGR3,     16'h0003);      // See Program code.(R3 <= R3 + 1)
600
 
601
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Do a Single Step (R3 <= R3 + 1)
602
    repeat(5) @(posedge mstr_test_clk);
603
    u0.wb_cmp(0, XGATE_XGPC,     16'h204c);      // PC + 2.
604
 
605
    repeat(5) @(posedge mstr_test_clk);
606
 
607
    data_xgmctl = XGMCTL_XGDBGM;
608
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Debug Mode Control Bit
609
                                                 // Should be back in Run Mode
610
    wait_irq_set(1);
611
    u0.wb_write(1, XGATE_XGIF_0, 16'h0002);
612 21 rehayes
 
613 11 rehayes
    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
614
    u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Software Interrupt and BRK Interrupt Enable Bit
615
    repeat(15) @(posedge mstr_test_clk);
616 21 rehayes
 
617 2 rehayes
  end
618
endtask
619
 
620 11 rehayes
// Test instruction set
621
task test_inst_set;
622
  begin
623 21 rehayes
    $readmemh("../../../bench/verilog/inst_test.v", ram_8);
624 11 rehayes
    test_num = test_num + 1;
625
    $display("\nTEST #%d Starts at vector=%d, inst_test", test_num, vector);
626 21 rehayes
    repeat(1) @(posedge mstr_test_clk);
627 11 rehayes
 
628
    activate_thread_sw(1);
629
    wait_irq_set(1);
630
    u0.wb_write(1, XGATE_XGIF_0, 16'h0002);
631 21 rehayes
 
632 11 rehayes
    activate_thread_sw(2);
633
    wait_irq_set(2);
634
    u0.wb_write(1, XGATE_XGIF_0, 16'h0004);
635
 
636
    activate_thread_sw(3);
637
    wait_irq_set(3);
638
    u0.wb_write(1, XGATE_XGIF_0, 16'h0008);
639 21 rehayes
 
640 11 rehayes
    activate_thread_sw(4);
641
    wait_irq_set(4);
642
    u0.wb_write(1, XGATE_XGIF_0, 16'h0010);
643 21 rehayes
 
644 11 rehayes
    activate_thread_sw(5);
645
    wait_irq_set(5);
646
    u0.wb_write(1, XGATE_XGIF_0, 16'h0020);
647 21 rehayes
 
648 11 rehayes
    activate_thread_sw(6);
649
    wait_irq_set(6);
650
    u0.wb_write(1, XGATE_XGIF_0, 16'h0040);
651 21 rehayes
 
652 11 rehayes
    activate_thread_sw(7);
653
    wait_irq_set(7);
654
    u0.wb_write(1, XGATE_XGIF_0, 16'h0080);
655 21 rehayes
 
656 11 rehayes
    activate_thread_sw(8);
657
    wait_irq_set(8);
658
    u0.wb_write(1, XGATE_XGIF_0, 16'h0100);
659 21 rehayes
 
660 11 rehayes
    activate_thread_sw(9);
661
    wait_irq_set(9);
662
    u0.wb_write(1, XGATE_XGIF_0, 16'h0200);
663 21 rehayes
 
664 11 rehayes
    u0.wb_write(1, XGATE_XGSEM, 16'h5050);
665
    u0.wb_cmp(0, XGATE_XGSEM,    16'h0050);   //
666
    activate_thread_sw(10);
667
    wait_irq_set(10);
668
    u0.wb_write(1, XGATE_XGIF_0, 16'h0400);
669 21 rehayes
 
670 11 rehayes
    u0.wb_write(1, XGATE_XGSEM, 16'hff00);    // clear the old settings
671
    u0.wb_cmp(0, XGATE_XGSEM,    16'h0000);   //
672
    u0.wb_write(1, XGATE_XGSEM, 16'ha0a0);    // Verify that bits were unlocked by RISC
673
    u0.wb_cmp(0, XGATE_XGSEM,    16'h00a0);   // Verify bits were set
674
    u0.wb_write(1, XGATE_XGSEM, 16'hff08);    // Try to set the bit that was left locked by the RISC
675
    u0.wb_cmp(0, XGATE_XGSEM,    16'h0000);   // Verify no bits were set
676 21 rehayes
 
677 11 rehayes
    repeat(20) @(posedge mstr_test_clk);
678
 
679
    dump_ram(0);
680
  end
681
endtask
682
 
683 2 rehayes
// check register bits - reset, read/write
684
task reg_test_16;
685
  begin
686
      test_num = test_num + 1;
687
      $display("TEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
688
      u0.wb_cmp(0, XGATE_XGMCTL,   16'h0000);   // verify reset
689
      u0.wb_cmp(0, XGATE_XGCHID,   16'h0000);   // verify reset
690
      u0.wb_cmp(0, XGATE_XGISPHI,  16'h0000);   // verify reset
691
      u0.wb_cmp(0, XGATE_XGISPLO,  16'h0000);   // verify reset
692
      u0.wb_cmp(0, XGATE_XGVBR,    16'h0000);   // verify reset
693
      u0.wb_cmp(0, XGATE_XGIF_7,   16'h0000);   // verify reset
694
      u0.wb_cmp(0, XGATE_XGIF_6,   16'h0000);   // verify reset
695
      u0.wb_cmp(0, XGATE_XGIF_5,   16'h0000);   // verify reset
696
      u0.wb_cmp(0, XGATE_XGIF_4,   16'h0000);   // verify reset
697
      u0.wb_cmp(0, XGATE_XGIF_3,   16'h0000);   // verify reset
698
      u0.wb_cmp(0, XGATE_XGIF_2,   16'h0000);   // verify reset
699
      u0.wb_cmp(0, XGATE_XGIF_1,   16'h0000);   // verify reset
700
      u0.wb_cmp(0, XGATE_XGIF_0,   16'h0000);   // verify reset
701
      u0.wb_cmp(0, XGATE_XGSWT,    16'h0000);   // verify reset
702
      u0.wb_cmp(0, XGATE_XGSEM,    16'h0000);   // verify reset
703
      u0.wb_cmp(0, XGATE_XGCCR,    16'h0000);   // verify reset
704
      u0.wb_cmp(0, XGATE_XGPC,     16'h0000);   // verify reset
705
      u0.wb_cmp(0, XGATE_XGR1,     16'h0000);   // verify reset
706
      u0.wb_cmp(0, XGATE_XGR2,     16'h0000);   // verify reset
707
      u0.wb_cmp(0, XGATE_XGR3,     16'h0000);   // verify reset
708
      u0.wb_cmp(0, XGATE_XGR4,     16'h0000);   // verify reset
709
      u0.wb_cmp(0, XGATE_XGR5,     16'h0000);   // verify reset
710
      u0.wb_cmp(0, XGATE_XGR6,     16'h0000);   // verify reset
711
      u0.wb_cmp(0, XGATE_XGR7,     16'h0000);   // verify reset
712
 
713
      u0.wb_write(1, XGATE_XGR1, 16'h5555);
714
      u0.wb_cmp(  0, XGATE_XGR1, 16'h5555);
715
      u0.wb_write(1, XGATE_XGR2, 16'haaaa);
716
      u0.wb_cmp(  0, XGATE_XGR2, 16'haaaa);
717
      u0.wb_write(1, XGATE_XGR3, 16'h9999);
718
      u0.wb_cmp(  0, XGATE_XGR3, 16'h9999);
719
      u0.wb_write(1, XGATE_XGR4, 16'hcccc);
720
      u0.wb_cmp(  0, XGATE_XGR4, 16'hcccc);
721
      u0.wb_write(1, XGATE_XGR5, 16'h3333);
722
      u0.wb_cmp(  0, XGATE_XGR5, 16'h3333);
723
      u0.wb_write(1, XGATE_XGR6, 16'h6666);
724
      u0.wb_cmp(  0, XGATE_XGR6, 16'h6666);
725
      u0.wb_write(1, XGATE_XGR7, 16'ha5a5);
726
      u0.wb_cmp(  0, XGATE_XGR7, 16'ha5a5);
727
 
728
      u0.wb_write(1, XGATE_XGPC, 16'h5a5a);
729
      u0.wb_cmp(  0, XGATE_XGPC, 16'h5a5a);
730
 
731
      u0.wb_write(1, XGATE_XGCCR, 16'hfffa);
732
      u0.wb_cmp(  0, XGATE_XGCCR, 16'h000a);
733
      u0.wb_write(1, XGATE_XGCCR, 16'hfff5);
734
      u0.wb_cmp(  0, XGATE_XGCCR, 16'h0005);
735
 
736
  end
737
endtask
738
 
739
 
740 11 rehayes
// Poll for XGATE Interrupt set
741
task wait_irq_set;
742
  input [ 6:0] chan_val;
743
  begin
744
    while(!xgif[chan_val])
745
      @(posedge mstr_test_clk); // poll it until it is set
746
    $display("XGATE Interrupt Request #%d set detected at vector =%d", chan_val, vector);
747
  end
748
endtask
749 2 rehayes
 
750 11 rehayes
// Poll for debug bit set
751
task wait_debug_set;
752
  begin
753
    u0.wb_read(1, XGATE_XGMCTL, q);
754
    while(~|(q & XGMCTL_XGDBG))
755
      u0.wb_read(1, XGATE_XGMCTL, q); // poll it until it is set
756
    $display("DEBUG Flag set detected at vector =%d", vector);
757
  end
758
endtask
759 2 rehayes
 
760 11 rehayes
 
761 2 rehayes
task system_reset;  // reset system
762
  begin
763
      repeat(1) @(posedge mstr_test_clk);
764
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
765
      #2;                 // move the async reset away from the clock edge
766
      rstn = 1'b0;        // assert async reset
767
      #5;                 // Keep the async reset pulse with less than a clock cycle
768
      rstn = 1'b1;        // negate async reset
769
      repeat(1) @(posedge mstr_test_clk);
770
      sync_reset = 1'b0;
771
 
772
      $display("\nstatus: %t System Reset Task Done", $time);
773
      test_num = test_num + 1;
774
 
775
      repeat(2) @(posedge mstr_test_clk);
776
   end
777
endtask
778
 
779
 
780
task activate_channel;
781
  input [ 6:0] chan_val;
782
  begin
783 21 rehayes
    $display("Activating Channel %d", chan_val);
784 2 rehayes
 
785 21 rehayes
    channel_req[chan_val] = 1'b1; //
786
    repeat(1) @(posedge mstr_test_clk);
787 2 rehayes
  end
788
endtask
789
 
790
 
791
task clear_channel;
792
  input [ 6:0] chan_val;
793
  begin
794 21 rehayes
    $display("Clearing Channel interrupt input #%d", chan_val);
795 2 rehayes
 
796 21 rehayes
    channel_req[chan_val] = 1'b0; //
797
    repeat(1) @(posedge mstr_test_clk);
798
  end
799 2 rehayes
endtask
800
 
801
 
802
task clear_irq_flag;
803
  input [ 6:0] chan_val;
804
  begin
805
      $display("Clearing Channel interrupt flag #%d", chan_val);
806
      if (0 < chan_val < 16)
807
        u0.wb_write(1, XGATE_XGIF_0, 16'hffff);
808
      if (15 < chan_val < 32)
809
        u0.wb_write(1, XGATE_XGIF_1, 16'hffff);
810
      if (31 < chan_val < 48)
811
        u0.wb_write(1, XGATE_XGIF_2, 16'hffff);
812
      if (47 < chan_val < 64)
813
        u0.wb_write(1, XGATE_XGIF_3, 16'hffff);
814
      if (63 < chan_val < 80)
815
        u0.wb_write(1, XGATE_XGIF_4, 16'hffff);
816
      if (79 < chan_val < 96)
817
        u0.wb_write(1, XGATE_XGIF_5, 16'hffff);
818
      if (95 < chan_val < 112)
819
        u0.wb_write(1, XGATE_XGIF_6, 16'hffff);
820
      if (111 < chan_val < 128)
821
        u0.wb_write(1, XGATE_XGIF_7, 16'hffff);
822
 
823 21 rehayes
      channel_req[chan_val] = 1'b0; //
824 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
825
   end
826
endtask
827
 
828
 
829
task activate_thread_sw;
830
  input [ 6:0] chan_val;
831
  begin
832
      $display("Activating Sofrware Thread - Channel #%d", chan_val);
833
 
834 11 rehayes
      data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
835
      u0.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Enable XGATE
836 2 rehayes
 
837 21 rehayes
      channel_req[chan_val] = 1'b1; //
838 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
839
   end
840
endtask
841
 
842
task dump_ram;
843
  input [15:0] start_address;
844
  reg   [15:0] dump_address;
845
  integer i, j;
846
  begin
847
      $display("Dumping RAM - Starting Address #%h", start_address);
848 21 rehayes
 
849 2 rehayes
      dump_address = start_address;
850
      while (dump_address <= start_address + 16'h0080)
851 21 rehayes
        begin
852
          $write("Address = %h", dump_address);
853 2 rehayes
          for (i = 0; i < 16; i = i + 1)
854
            begin
855 21 rehayes
              $write(" %h", ram_8[dump_address]);
856
              dump_address = dump_address + 1;
857
            end
858
        $write("\n");
859
        end
860 2 rehayes
 
861
  end
862
endtask
863
 
864 5 rehayes
task wrap_up;
865
  begin
866 21 rehayes
    test_num = test_num + 1;
867
    repeat(10) @(posedge mstr_test_clk);
868 5 rehayes
    $display("\nSimulation Finished!! - vector =%d", vector);
869
    if (error_count == 0)
870
      $display("Simulation Passed");
871
    else
872 21 rehayes
      $display("Simulation Failed  --- Errors =%d", error_count);
873 5 rehayes
 
874
    $finish;
875
  end
876
endtask
877
 
878 2 rehayes
function [15:0] four_2_16;
879
  input [3:0] vector;
880
  begin
881
    case (vector)
882
      4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
883
      4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
884
      4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
885
      4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
886
      4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
887
      4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
888
      4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
889
      4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
890
      4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
891
      4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
892
      4'ha : four_2_16 = 16'b0000_0100_0000_0000;
893
      4'hb : four_2_16 = 16'b0000_1000_0000_0000;
894
      4'hc : four_2_16 = 16'b0001_0000_0000_0000;
895
      4'hd : four_2_16 = 16'b0010_0000_0000_0000;
896
      4'he : four_2_16 = 16'b0100_0000_0000_0000;
897
      4'hf : four_2_16 = 16'b1000_0000_0000_0000;
898
    endcase
899
  end
900
endfunction
901
 
902
endmodule  // tst_bench_top
903
 

powered by: WebSVN 2.1.0

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