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

Subversion Repositories xgate

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

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

powered by: WebSVN 2.1.0

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