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

Subversion Repositories xgate

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

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 62 rehayes
//          rehayes@opencores.org
7 2 rehayes
//
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 62 rehayes
//       notice, this list of conditions and the following disclaimer.
21 2 rehayes
//     * Neither the name of the <organization> nor the
22 62 rehayes
//       names of its contributors may be used to endorse or promote products
23
//       derived from this software without specific prior written permission.
24 2 rehayes
//
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 62 rehayes
  parameter MAX_CHANNEL = 127;    // Max XGATE Interrupt Channel Number
47 5 rehayes
  parameter STOP_ON_ERROR = 1'b0;
48 65 rehayes
  parameter MAX_VECTOR = 9000;
49 21 rehayes
 
50 41 rehayes
  parameter L_BYTE = 2'b01;
51
  parameter H_BYTE = 2'b10;
52 36 rehayes
  parameter WORD   = 2'b11;
53 21 rehayes
 
54 2 rehayes
 
55
  // Name Address Locations
56 62 rehayes
  parameter XGATE_BASE     = 24'h1000;
57 41 rehayes
  parameter XGATE_XGMCTL   = XGATE_BASE + 6'h00;
58
  parameter XGATE_XGCHID   = XGATE_BASE + 6'h02;
59
  parameter XGATE_XGISPHI  = XGATE_BASE + 6'h04;
60
  parameter XGATE_XGISPLO  = XGATE_BASE + 6'h06;
61 62 rehayes
  parameter XGATE_XGVBR    = XGATE_BASE + 6'h08;
62 41 rehayes
  parameter XGATE_XGIF_7   = XGATE_BASE + 6'h0a;
63
  parameter XGATE_XGIF_6   = XGATE_BASE + 6'h0c;
64
  parameter XGATE_XGIF_5   = XGATE_BASE + 6'h0e;
65
  parameter XGATE_XGIF_4   = XGATE_BASE + 6'h10;
66
  parameter XGATE_XGIF_3   = XGATE_BASE + 6'h12;
67
  parameter XGATE_XGIF_2   = XGATE_BASE + 6'h14;
68
  parameter XGATE_XGIF_1   = XGATE_BASE + 6'h16;
69
  parameter XGATE_XGIF_0   = XGATE_BASE + 6'h18;
70 62 rehayes
  parameter XGATE_XGSWT    = XGATE_BASE + 6'h1a;
71
  parameter XGATE_XGSEM    = XGATE_BASE + 6'h1c;
72
  parameter XGATE_RES1     = XGATE_BASE + 6'h1e;
73
  parameter XGATE_XGCCR    = XGATE_BASE + 6'h20;
74
  parameter XGATE_XGPC     = XGATE_BASE + 6'h22;
75
  parameter XGATE_RES2     = XGATE_BASE + 6'h24;
76
  parameter XGATE_XGR1     = XGATE_BASE + 6'h26;
77
  parameter XGATE_XGR2     = XGATE_BASE + 6'h28;
78
  parameter XGATE_XGR3     = XGATE_BASE + 6'h2a;
79
  parameter XGATE_XGR4     = XGATE_BASE + 6'h2c;
80
  parameter XGATE_XGR5     = XGATE_BASE + 6'h2e;
81
  parameter XGATE_XGR6     = XGATE_BASE + 6'h30;
82
  parameter XGATE_XGR7     = XGATE_BASE + 6'h32;
83 21 rehayes
 
84 11 rehayes
  // Define bits in XGATE Control Register
85 62 rehayes
  parameter XGMCTL_XGEM     = 16'h8000;
86 11 rehayes
  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 62 rehayes
  parameter XGMCTL_XGE      = 16'h0080;
94 11 rehayes
  parameter XGMCTL_XGFRZ    = 16'h0040;
95
  parameter XGMCTL_XGDBG    = 15'h0020;
96 62 rehayes
  parameter XGMCTL_XGSS     = 15'h0010;
97 11 rehayes
  parameter XGMCTL_XGFACT   = 15'h0008;
98
  parameter XGMCTL_XGBRKIE  = 15'h0004;
99
  parameter XGMCTL_XGSWEIF  = 15'h0002;
100 62 rehayes
  parameter XGMCTL_XGIE     = 15'h0001;
101 2 rehayes
 
102 68 rehayes
  parameter CHECK_POINT     = 16'h8000;
103
  parameter CHANNEL_ACK     = CHECK_POINT + 2;
104
  parameter CHANNEL_ERR     = CHECK_POINT + 4;
105
  parameter TB_SEMPHORE     = CHECK_POINT + 10;
106
  parameter CHANNEL_XGIRQ_0 = CHECK_POINT + 16;
107
  parameter CHANNEL_XGIRQ_1 = CHECK_POINT + 18;
108
  parameter CHANNEL_XGIRQ_2 = CHECK_POINT + 20;
109
  parameter CHANNEL_XGIRQ_3 = CHECK_POINT + 22;
110
  parameter CHANNEL_XGIRQ_4 = CHECK_POINT + 24;
111
  parameter CHANNEL_XGIRQ_5 = CHECK_POINT + 26;
112
  parameter CHANNEL_XGIRQ_6 = CHECK_POINT + 28;
113
  parameter CHANNEL_XGIRQ_7 = CHECK_POINT + 30;
114 36 rehayes
 
115 62 rehayes
  parameter SYS_RAM_BASE = 24'h00_0000;
116 65 rehayes
 
117 68 rehayes
  parameter RAM_WAIT_STATES = 1; // Number between 0 and 15
118
  parameter SYS_READ_DELAY  = 10;
119 65 rehayes
  parameter XGATE_ACCESS_DELAY = SYS_READ_DELAY + RAM_WAIT_STATES;
120
  parameter XGATE_SS_DELAY = XGATE_ACCESS_DELAY + RAM_WAIT_STATES;
121 62 rehayes
 
122 68 rehayes
  parameter IRQ_BASE       = XGATE_BASE + 64;
123
  parameter IRQ_BYPS_0     = IRQ_BASE + 0;
124
  parameter IRQ_BYPS_1     = IRQ_BASE + 2;
125
  parameter IRQ_BYPS_2     = IRQ_BASE + 4;
126
  parameter IRQ_BYPS_3     = IRQ_BASE + 6;
127
  parameter IRQ_BYPS_4     = IRQ_BASE + 8;
128
  parameter IRQ_BYPS_5     = IRQ_BASE + 10;
129
  parameter IRQ_BYPS_6     = IRQ_BASE + 12;
130
  parameter IRQ_BYPS_7     = IRQ_BASE + 14;
131 65 rehayes
 
132 36 rehayes
  //
133
  // wires && regs
134
  //
135 62 rehayes
  reg         mstr_test_clk;
136 36 rehayes
  reg  [19:0] vector;
137
  reg  [15:0] error_count;
138
  reg  [ 7:0] test_num;
139 62 rehayes
 
140 36 rehayes
  reg  [15:0] q, qq;
141 21 rehayes
 
142 62 rehayes
  reg         rstn;
143
  reg         sync_reset;
144
  reg         por_reset_b;
145
  reg         scantestmode;
146 21 rehayes
 
147 73 rehayes
  reg  [MAX_CHANNEL:1] channel_req;  // XGATE Interrupt inputs
148
  wire [MAX_CHANNEL:1] xgif;         // XGATE Interrupt outputs
149 62 rehayes
  wire         [  7:0] xgswt;         // XGATE Software Trigger outputs
150
  wire                 xg_sw_irq;    // Xgate Software Error interrupt
151 36 rehayes
 
152
 
153 62 rehayes
  wire [15:0] wbm_dat_o;  // WISHBONE Master Mode data output from XGATE
154
  wire [15:0] wbm_dat_i;  // WISHBONE Master Mode data input to XGATE
155
  wire [15:0] wbm_adr_o;  // WISHBONE Master Mode address output from XGATE
156 36 rehayes
  wire [ 1:0] wbm_sel_o;
157
 
158 62 rehayes
  reg         mem_wait_state_enable;
159 36 rehayes
 
160
  wire [15:0] tb_ram_out;
161
 
162 62 rehayes
  wire [15:0] tb_slave_dout; // WISHBONE data bus output from testbench slave module
163
  wire        error_pulse;   // Error detected output pulse from the testbench slave module
164 68 rehayes
  wire        tb_slave_ack;  // WISHBONE ack from testbench slave module
165 62 rehayes
  wire        ack_pulse;     // Thread ack output pulse from testbench slave module
166
 
167
  wire        wbm_cyc_o;
168
  wire        wbm_stb_o;
169
  wire        wbm_we_o;
170
  wire        wbs_err_o;
171
 
172
 
173 11 rehayes
  // Registers used to mirror internal registers
174 36 rehayes
  reg  [15:0] data_xgmctl;
175
  reg  [15:0] data_xgchid;
176
  reg  [15:0] data_xgvbr;
177
  reg  [15:0] data_xgswt;
178
  reg  [15:0] data_xgsem;
179 2 rehayes
 
180 62 rehayes
  wire        sys_cyc;
181
  wire        sys_stb;
182
  wire        sys_we;
183 36 rehayes
  wire [ 1:0] sys_sel;
184 54 rehayes
  wire [23:0] sys_adr;
185 36 rehayes
  wire [15:0] sys_dout;
186 54 rehayes
  wire [15:0] sys_din;
187 62 rehayes
 
188
  wire        host_ack;
189 36 rehayes
  wire [15:0] host_dout;
190 62 rehayes
  wire        host_cyc;
191
  wire        host_stb;
192
  wire        host_we;
193 36 rehayes
  wire [ 1:0] host_sel;
194 54 rehayes
  wire [23:0] host_adr;
195 36 rehayes
  wire [15:0] host_din;
196 62 rehayes
 
197
  wire        xgate_ack;
198 36 rehayes
  wire [15:0] xgate_dout;
199 62 rehayes
  wire        xgate_cyc;
200
  wire        xgate_stb;
201
  wire        xgate_we;
202 36 rehayes
  wire [ 1:0] xgate_sel;
203
  wire [15:0] xgate_adr;
204
  wire [15:0] xgate_din;
205 62 rehayes
 
206
  wire        xgate_s_stb;
207
  wire        xgate_s_ack;
208 36 rehayes
  wire [15:0] xgate_s_dout;
209 62 rehayes
 
210
  wire        slv2_stb;
211
  wire        ram_sel;
212 36 rehayes
  wire [15:0] ram_dout;
213
 
214 2 rehayes
  // initial values and testbench setup
215
  initial
216
    begin
217
      mstr_test_clk = 0;
218
      vector = 0;
219
      test_num = 0;
220
      por_reset_b = 0;
221
      scantestmode = 0;
222 5 rehayes
      error_count = 0;
223 11 rehayes
      mem_wait_state_enable = 0;
224 2 rehayes
      // channel_req = 0;
225
 
226
      `ifdef WAVES
227 62 rehayes
           $shm_open("waves");
228
           $shm_probe("AS",tst_bench_top,"AS");
229
           $display("\nINFO: Signal dump enabled ...\n\n");
230 2 rehayes
      `endif
231
 
232
      `ifdef WAVES_V
233 62 rehayes
           $dumpfile ("xgate_wave_dump.lxt");
234
           $dumpvars (0, tst_bench_top);
235
           $dumpon;
236
           $display("\nINFO: VCD Signal dump enabled ...\n\n");
237 2 rehayes
      `endif
238
 
239
    end
240
 
241
  // generate clock
242
  always #20 mstr_test_clk = ~mstr_test_clk;
243
 
244 5 rehayes
  // Keep a count of how many clocks we've simulated
245 2 rehayes
  always @(posedge mstr_test_clk)
246 11 rehayes
    begin
247
      vector <= vector + 1;
248
      if (vector > MAX_VECTOR)
249 62 rehayes
        begin
250
          error_count <= error_count + 1;
251
          $display("\n ------ !!!!! Simulation Timeout at vector=%d\n -------", vector);
252
          wrap_up;
253
        end
254 11 rehayes
    end
255 2 rehayes
 
256 50 rehayes
  // Add up errors that come from WISHBONE read compares
257 36 rehayes
  always @host.cmp_error_detect
258 21 rehayes
    begin
259
      error_count <= error_count + 1;
260
    end
261 11 rehayes
 
262 54 rehayes
  always @(posedge error_pulse) //channel_ack_wrt
263 2 rehayes
    begin
264 54 rehayes
      #1;
265 5 rehayes
      error_count = error_count + 1;
266
      if (STOP_ON_ERROR == 1'b1)
267 62 rehayes
        wrap_up;
268 5 rehayes
    end
269
 
270 2 rehayes
  wire [ 6:0] current_active_channel = xgate.risc.xgchid;
271 54 rehayes
  always @(posedge ack_pulse) //channel_ack_wrt
272 2 rehayes
    clear_channel(current_active_channel);
273 21 rehayes
 
274 2 rehayes
 
275 62 rehayes
 
276 36 rehayes
  // Testbench RAM for Xgate program storage and Load/Store instruction tests
277
  ram p_ram
278
  (
279
    // Outputs
280
    .ram_out( ram_dout ),
281
    // inputs
282 54 rehayes
    .address( sys_adr[15:0] ),
283 36 rehayes
    .ram_in( sys_dout ),
284
    .we( sys_we ),
285 54 rehayes
    .ce( ram_sel ),
286 36 rehayes
    .stb( mstr_test_clk ),
287 54 rehayes
    .sel( sys_sel )
288 36 rehayes
  );
289
 
290
  // hookup wishbone master model
291 54 rehayes
  wb_master_model #(.dwidth(16), .awidth(24))
292 36 rehayes
    host(
293
    // Outputs
294
    .cyc( host_cyc ),
295
    .stb( host_stb ),
296
    .we( host_we ),
297
    .sel( host_sel ),
298
    .adr( host_adr ),
299
    .dout( host_dout ),
300
    // inputs
301 68 rehayes
    .din( sys_din ),
302
    .clk( mstr_test_clk ),
303
    .ack( host_ack ),
304
    .rst( rstn ),
305
    .err( 1'b0 ),
306
    .rty( 1'b0 )
307 36 rehayes
  );
308
 
309
  bus_arbitration  #(.dwidth(16),
310 62 rehayes
                     .awidth(24),
311 54 rehayes
                     .ram_base(0),
312
                     .ram_size(17'h10000),
313
                     .slv1_base(XGATE_BASE),
314 68 rehayes
                     .slv1_size(128),
315 54 rehayes
                     .slv2_base(CHECK_POINT),
316 68 rehayes
                     .slv2_size(32),
317 65 rehayes
                     .ram_wait_states(RAM_WAIT_STATES)
318
)
319 36 rehayes
    arb(
320
    // System bus I/O
321
    .sys_cyc( sys_cyc ),
322
    .sys_stb( sys_stb ),
323
    .sys_we( sys_we ),
324
    .sys_sel( sys_sel ),
325
    .sys_adr( sys_adr ),
326
    .sys_dout( sys_dout ),
327 54 rehayes
    .sys_din( sys_din ),
328 36 rehayes
    // Host bus I/O
329
    .host_ack( host_ack ),
330
    .host_dout( host_din ),
331
    .host_cyc( host_cyc ),
332
    .host_stb( host_stb ),
333
    .host_we( host_we ),
334
    .host_sel( host_sel ),
335
    .host_adr( host_adr ),
336
    .host_din( host_dout ),
337
    // Alternate Bus Master #1 Bus I/O
338
    .alt1_ack( xgate_ack ),
339
    .alt1_cyc( wbm_cyc_o ),
340
    .alt1_stb( wbm_stb_o ),
341
    .alt1_we( wbm_we_o ),
342
    .alt1_sel( wbm_sel_o ),
343 54 rehayes
    .alt1_adr( {8'h00, wbm_adr_o} ),
344 36 rehayes
    .alt1_din( wbm_dat_o ),
345 54 rehayes
    // RAM
346
    .ram_sel( ram_sel ),
347
    .ram_dout( ram_dout ),
348 36 rehayes
    // Slave #1 Bus I/O
349
    .slv1_stb( xgate_s_stb ),
350
    .slv1_ack( xgate_s_ack ),
351
    .slv1_din( xgate_s_dout ),
352
    // Slave #2 Bus I/O
353
    .slv2_stb( slv2_stb ),
354 68 rehayes
    .slv2_ack( tb_slave_ack ),
355 62 rehayes
    .slv2_din( tb_slave_dout ),
356 36 rehayes
    // Miscellaneous
357
    .host_clk( mstr_test_clk ),
358
    .risc_clk( mstr_test_clk ),
359
    .rst( rstn ),  // No Connect
360
    .err( 1'b0 ),  // No Connect
361
    .rty( 1'b0 )   // No Connect
362
  );
363 62 rehayes
 
364 5 rehayes
  // hookup XGATE core - Parameters take all default values
365 54 rehayes
  xgate_top  #(.SINGLE_CYCLE(1'b0),
366 68 rehayes
               .WB_RD_DEFAULT(1'b0),
367 62 rehayes
               .MAX_CHANNEL(MAX_CHANNEL))    // Max XGATE Interrupt Channel Number
368
          xgate(
369
          // Wishbone slave interface
370
          .wbs_clk_i( mstr_test_clk ),
371
          .wbs_rst_i( 1'b0 ),         // sync_reset
372
          .arst_i( rstn ),            // async resetn
373 68 rehayes
          .wbs_adr_i( sys_adr[6:1] ),
374 62 rehayes
          .wbs_dat_i( sys_dout ),
375
          .wbs_dat_o( xgate_s_dout ),
376
          .wbs_we_i( sys_we ),
377
          .wbs_stb_i( xgate_s_stb ),
378
          .wbs_cyc_i( sys_cyc ),
379
          .wbs_sel_i( sys_sel ),
380
          .wbs_ack_o( xgate_s_ack ),
381
          .wbs_err_o( wbs_err_o ),
382 2 rehayes
 
383 62 rehayes
          // Wishbone master Signals
384
          .wbm_dat_o( wbm_dat_o ),
385
          .wbm_we_o( wbm_we_o ),
386
          .wbm_stb_o( wbm_stb_o ),
387
          .wbm_cyc_o( wbm_cyc_o ),
388
          .wbm_sel_o( wbm_sel_o ),
389
          .wbm_adr_o( wbm_adr_o ),
390
          .wbm_dat_i( sys_din ),
391
          .wbm_ack_i( xgate_ack ),
392 5 rehayes
 
393 62 rehayes
          .xgif( xgif ),             // XGATE Interrupt Flag output
394
          .xg_sw_irq( xg_sw_irq ),   // XGATE Software Error Interrupt Flag output
395
          .xgswt( xgswt ),
396
          .risc_clk( mstr_test_clk ),
397 73 rehayes
          .chan_req_i( {channel_req[MAX_CHANNEL:40], xgswt, channel_req[31:1]} ),
398 62 rehayes
          .debug_mode_i( 1'b0 ),
399
          .secure_mode_i( 1'b0 ),
400
          .scantestmode( scantestmode )
401 2 rehayes
  );
402
 
403 54 rehayes
  tb_slave #(.DWIDTH(16),
404 68 rehayes
             .SINGLE_CYCLE(1'b1),
405
             .MAX_CHANNEL(MAX_CHANNEL))
406 54 rehayes
          tb_slave_regs(
407
          // wishbone interface
408
          .wb_clk_i( mstr_test_clk ),
409
          .wb_rst_i( 1'b0 ),
410
          .arst_i( rstn ),
411 68 rehayes
          .wb_adr_i( sys_adr[4:1] ),
412 54 rehayes
          .wb_dat_i( sys_dout ),
413 62 rehayes
          .wb_dat_o( tb_slave_dout),
414 54 rehayes
          .wb_we_i( sys_we ),
415
          .wb_stb_i( slv2_stb ),
416
          .wb_cyc_i( sys_cyc ),
417
          .wb_sel_i( sys_sel ),
418 68 rehayes
          .wb_ack_o( tb_slave_ack ),
419 2 rehayes
 
420 62 rehayes
          .ack_pulse( ack_pulse ),
421 54 rehayes
          .error_pulse( error_pulse ),
422 65 rehayes
          .brk_pt(  ),
423
          .x_address( wbm_adr_o ),
424 68 rehayes
          .xgif( xgif ),
425 54 rehayes
          .vector( vector )
426
  );
427 2 rehayes
 
428 54 rehayes
 
429
 
430 2 rehayes
////////////////////////////////////////////////////////////////////////////////
431
////////////////////////////////////////////////////////////////////////////////
432
////////////////////////////////////////////////////////////////////////////////
433
 
434 54 rehayes
// Main Test Program
435 2 rehayes
initial
436
  begin
437 36 rehayes
    $display("\nstatus at time: %t Testbench started", $time);
438 2 rehayes
 
439 36 rehayes
    // reset system
440
    rstn = 1'b1; // negate reset
441
    channel_req = 1; //
442
    repeat(1) @(posedge mstr_test_clk);
443 62 rehayes
    sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
444
    #2;          // move the async reset away from the clock edge
445 36 rehayes
    rstn = 1'b0; // assert async reset
446 62 rehayes
    #5;          // Keep the async reset pulse with less than a clock cycle
447 36 rehayes
    rstn = 1'b1; // negate async reset
448
    por_reset_b = 1'b1;
449
    channel_req = 0; //
450
    repeat(1) @(posedge mstr_test_clk);
451
    sync_reset = 1'b0;
452
    channel_req = 0; //
453 2 rehayes
 
454 36 rehayes
    $display("\nstatus at time: %t done reset", $time);
455 21 rehayes
 
456 36 rehayes
    test_inst_set;
457 21 rehayes
 
458 36 rehayes
    test_debug_mode;
459 2 rehayes
 
460 36 rehayes
    test_debug_bit;
461 21 rehayes
 
462 36 rehayes
    test_chid_debug;
463 21 rehayes
 
464 41 rehayes
    reg_test_16;
465 68 rehayes
 
466
    reg_irq;
467 41 rehayes
 
468 68 rehayes
    // host_ram;
469 54 rehayes
 
470 36 rehayes
    // End testing
471
    wrap_up;
472 2 rehayes
  end
473
 
474 36 rehayes
////////////////////////////////////////////////////////////////////////////////
475 21 rehayes
// Test CHID Debug mode operation
476
task test_chid_debug;
477
  begin
478
    test_num = test_num + 1;
479
    $display("\nTEST #%d Starts at vector=%d, test_chid_debug", test_num, vector);
480 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
481 21 rehayes
 
482 68 rehayes
    // Enable interrupts to RISC
483
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
484
 
485 21 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
486 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Enable interrupt on BRK instruction
487 65 rehayes
    $display("BRK Software Error Interrupt enabled at vector=%d", vector);
488 21 rehayes
 
489
    activate_thread_sw(3);
490
 
491
    wait_debug_set;   // Debug Status bit is set by BRK instruction
492
 
493 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h20c6, WORD);      // See Program code (BRK).
494
    host.wb_cmp(0, XGATE_XGR3,      16'h0001, WORD);      // See Program code.R3 = 1
495
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);       // Check for Correct CHID
496 65 rehayes
    $display("Debug entry detected at vector=%d", vector);
497 21 rehayes
 
498
    channel_req[5] = 1'b1; //
499
    repeat(7) @(posedge mstr_test_clk);
500 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);       // Check for Correct CHID
501 21 rehayes
 
502 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h000f, H_BYTE);     // Check byte select lines
503 41 rehayes
    repeat(4) @(posedge mstr_test_clk);
504 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);       // Verify CHID is unchanged
505 21 rehayes
 
506 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h000f, L_BYTE);     // Change CHID
507
    host.wb_cmp(0, XGATE_XGCHID,   16'h000f, WORD);       // Check for Correct CHID
508 21 rehayes
 
509 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h0000, WORD);       // Change CHID to 00, RISC should go to IDLE state
510
 
511 21 rehayes
    repeat(1) @(posedge mstr_test_clk);
512
 
513 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h0004, WORD);       // Change CHID
514 21 rehayes
 
515
    repeat(8) @(posedge mstr_test_clk);
516 65 rehayes
    $display("Channel ID changed at vector=%d", vector);
517 21 rehayes
 
518 65 rehayes
 
519 21 rehayes
    data_xgmctl = XGMCTL_XGDBGM;
520 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
521 21 rehayes
 
522
    wait_debug_set;   // Debug Status bit is set by BRK instruction
523 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0004, WORD);       // Check for Correct CHID
524
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit (Excape from Break State and run)
525 21 rehayes
 
526
    wait_debug_set;   // Debug Status bit is set by BRK instruction
527 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0005, WORD);       // Check for Correct CHID
528 21 rehayes
    activate_channel(6);
529 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit (Excape from Break State and run)
530 21 rehayes
 
531
    wait_debug_set;   // Debug Status bit is set by BRK instruction
532 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0006, WORD);       // Check for Correct CHID
533
    host.wb_cmp(0, XGATE_XGPC,      16'h211c, WORD);      // See Program code (BRK)
534 21 rehayes
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
535 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step
536 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
537 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h211e, WORD);      // See Program code (BRA)
538
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step
539 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
540 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2122, WORD);      // See Program code ()
541 21 rehayes
 
542
    repeat(20) @(posedge mstr_test_clk);
543
 
544
    data_xgmctl = XGMCTL_XGDBGM;
545 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
546 21 rehayes
 
547
    repeat(50) @(posedge mstr_test_clk);
548
 
549 36 rehayes
    p_ram.dump_ram(0);
550
 
551 68 rehayes
    read_ram_cmp(16'h0000, 16'h7b55);
552
    read_ram_cmp(16'h0004, 16'h7faa);
553
    read_ram_cmp(16'h0006, 16'h6f55);
554
    read_ram_cmp(16'h0008, 16'h00c3);
555
    read_ram_cmp(16'h000a, 16'h5f66);
556
    read_ram_cmp(16'h000c, 16'h0003);
557
    read_ram_cmp(16'h0022, 16'hccxx);
558
    read_ram_cmp(16'h0026, 16'hxx99);
559
    read_ram_cmp(16'h0032, 16'h1fcc);
560
    read_ram_cmp(16'h0038, 16'h2f99);
561
    read_ram_cmp(16'h0042, 16'h33xx);
562
    read_ram_cmp(16'h0046, 16'hxx55);
563
    read_ram_cmp(16'h0052, 16'hxx66);
564
    read_ram_cmp(16'h0058, 16'h99xx);
565
    read_ram_cmp(16'h0062, 16'h1faa);
566
    read_ram_cmp(16'h0068, 16'h2fcc);
567 41 rehayes
 
568 21 rehayes
  end
569
endtask
570
 
571 36 rehayes
////////////////////////////////////////////////////////////////////////////////
572 11 rehayes
// Test Debug bit operation
573
task test_debug_bit;
574 2 rehayes
  begin
575 11 rehayes
    test_num = test_num + 1;
576 21 rehayes
    $display("\nTEST #%d Starts at vector=%d, test_debug_bit", test_num, vector);
577 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
578 21 rehayes
 
579 68 rehayes
    // Enable interrupts to RISC
580
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
581
 
582 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
583 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Enable interrupt on BRK instruction
584 11 rehayes
 
585
    activate_thread_sw(2);
586 21 rehayes
 
587 65 rehayes
    // Approxmatly 12 instructions need to be done before activating Debug Mode
588
    repeat(12 + RAM_WAIT_STATES*12) @(posedge mstr_test_clk);
589 11 rehayes
 
590
    data_xgmctl = XGMCTL_XGDBGM | XGMCTL_XGDBG;
591 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Set Debug Mode Control Bit
592 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
593 65 rehayes
    $display("DEBUG bit set at vector=%d", vector);
594 21 rehayes
 
595 36 rehayes
    host.wb_read(1, XGATE_XGR3, q, WORD);
596 21 rehayes
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
597
    qq = q;
598
 
599
    // The Xgate test program is in an infinate loop incrementing R3
600
    while (qq == q)  // Look for change in R3 register
601
      begin
602 62 rehayes
        host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step
603 65 rehayes
        repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
604 62 rehayes
        host.wb_read(1, XGATE_XGR3, q, WORD);
605 21 rehayes
      end
606
    if (q != (qq+1))
607
      begin
608 62 rehayes
        $display("Error! - Unexpected value of R3 at vector=%d", vector);
609
        error_count = error_count + 1;
610 21 rehayes
      end
611
 
612
 
613 62 rehayes
    host.wb_write(1, XGATE_XGPC, 16'h2094, WORD);        // Write to PC to force exit from infinite loop
614 54 rehayes
    repeat(10) @(posedge mstr_test_clk);
615 65 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2094, WORD);      // Verify Proram Counter was changed
616
    $display("Program Counter changed at vector=%d", vector);
617 21 rehayes
 
618
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
619 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load ADDL instruction)
620 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
621 62 rehayes
    host.wb_cmp(0, XGATE_XGR4,      16'h0002, WORD);      // See Program code.(R4 <= R4 + 1)
622 21 rehayes
 
623 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load ADDL instruction)
624 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
625 62 rehayes
    host.wb_cmp(0, XGATE_XGR4,      16'h0003, WORD);      // See Program code.(R4 <= R4 + 1)
626 21 rehayes
 
627
    data_xgmctl = XGMCTL_XGDBGM;
628 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
629
                                                 // Should be back in Run Mode
630 21 rehayes
 
631
//    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
632 36 rehayes
//    host.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Software Interrupt and BRK Interrupt Enable Bit
633 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
634 21 rehayes
 
635 2 rehayes
  end
636
endtask
637
 
638 36 rehayes
////////////////////////////////////////////////////////////////////////////////
639 11 rehayes
// Test Debug mode operation
640
task test_debug_mode;
641 2 rehayes
  begin
642 11 rehayes
    test_num = test_num + 1;
643
    $display("\nTEST #%d Starts at vector=%d, test_debug_mode", test_num, vector);
644 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
645 21 rehayes
 
646 68 rehayes
    // Enable interrupts to RISC
647
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
648
 
649 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
650 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Enable interrupt on BRK instruction
651 11 rehayes
 
652
    activate_thread_sw(1);
653 21 rehayes
 
654 11 rehayes
    wait_debug_set;   // Debug Status bit is set by BRK instruction
655
 
656 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h203a, WORD);      // See Program code (BRK).
657
    host.wb_cmp(0, XGATE_XGR3,      16'h0001, WORD);      // See Program code.R3 = 1
658 11 rehayes
 
659
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
660
 
661 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load ADDL instruction)
662 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
663 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h203c, WORD);      // PC + 2.
664 11 rehayes
 
665 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load NOP instruction)
666 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute ADDL instruction
667 62 rehayes
    host.wb_cmp(0, XGATE_XGR3,      16'h0002, WORD);      // See Program code.(R3 <= R3 + 1)
668
    host.wb_cmp(0, XGATE_XGCCR,     16'h0000, WORD);      // See Program code.
669
    host.wb_cmp(0, XGATE_XGPC,      16'h203e, WORD);      // PC + 2.
670 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
671 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h203e, WORD);      // Still no change.
672 11 rehayes
 
673 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load BRA instruction)
674 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute NOP instruction
675 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2040, WORD);      // See Program code.
676 11 rehayes
 
677
 
678 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step
679 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute BRA instruction
680 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2064, WORD);      // PC = Branch destination.
681
                                                         // Load ADDL instruction
682 21 rehayes
 
683 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load LDW R7 instruction)
684 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute ADDL instruction
685 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2066, WORD);      // PC + 2.
686
    host.wb_cmp(0, XGATE_XGR3,      16'h0003, WORD);      // See Program code.(R3 <= R3 + 1)
687 11 rehayes
 
688 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (LDW R7)
689 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
690 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2068, WORD);      // PC + 2.
691
    host.wb_cmp(0, XGATE_XGR7,      16'h00c3, WORD);      // See Program code
692 11 rehayes
 
693
    repeat(1) @(posedge mstr_test_clk);
694 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (BRA)
695 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
696 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2048, WORD);      // See Program code.
697 11 rehayes
 
698 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (STW R3)
699 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
700 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h204a, WORD);      // PC + 2.
701
    host.wb_cmp(0, XGATE_XGR3,      16'h0003, WORD);      // See Program code.(R3 <= R3 + 1)
702 11 rehayes
 
703 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (R3 <= R3 + 1)
704 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
705 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h204c, WORD);      // PC + 2.
706 11 rehayes
 
707 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
708 11 rehayes
 
709
    data_xgmctl = XGMCTL_XGDBGM;
710 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
711
                                                         // Should be back in Run Mode
712 11 rehayes
    wait_irq_set(1);
713 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
714 21 rehayes
 
715 11 rehayes
    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
716 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Software Interrupt and BRK Interrupt Enable Bit
717 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
718 21 rehayes
 
719 2 rehayes
  end
720
endtask
721
 
722 36 rehayes
////////////////////////////////////////////////////////////////////////////////
723 11 rehayes
// Test instruction set
724
task test_inst_set;
725
  begin
726 36 rehayes
    $readmemh("../../../bench/verilog/inst_test.v", p_ram.ram_8);
727 11 rehayes
    test_num = test_num + 1;
728 65 rehayes
    $display("\nTEST #%d Starts at vector=%d, test_inst_set", test_num, vector);
729 21 rehayes
    repeat(1) @(posedge mstr_test_clk);
730 68 rehayes
 
731
    // Enable interrupts to RISC
732
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
733 11 rehayes
 
734
    activate_thread_sw(1);
735
    wait_irq_set(1);
736 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
737 21 rehayes
 
738 11 rehayes
    activate_thread_sw(2);
739
    wait_irq_set(2);
740 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0004, WORD);
741 11 rehayes
 
742
    activate_thread_sw(3);
743
    wait_irq_set(3);
744 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0008, WORD);
745 21 rehayes
 
746 11 rehayes
    activate_thread_sw(4);
747
    wait_irq_set(4);
748 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0010, WORD);
749 21 rehayes
 
750 11 rehayes
    activate_thread_sw(5);
751
    wait_irq_set(5);
752 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0020, WORD);
753 21 rehayes
 
754 11 rehayes
    activate_thread_sw(6);
755
    wait_irq_set(6);
756 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0040, WORD);
757 21 rehayes
 
758 11 rehayes
    activate_thread_sw(7);
759
    wait_irq_set(7);
760 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0080, WORD);
761 21 rehayes
 
762 11 rehayes
    activate_thread_sw(8);
763
    wait_irq_set(8);
764 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0100, WORD);
765 21 rehayes
 
766 11 rehayes
    activate_thread_sw(9);
767
    wait_irq_set(9);
768 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0200, WORD);
769 21 rehayes
 
770 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'h5050, WORD);
771 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h0050, WORD);   //
772 11 rehayes
    activate_thread_sw(10);
773
    wait_irq_set(10);
774 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0400, WORD);
775 21 rehayes
 
776 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'hff00, WORD);    // clear the old settings
777 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h0000, WORD);   //
778 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'ha0a0, WORD);    // Verify that bits were unlocked by RISC
779 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h00a0, WORD);   // Verify bits were set
780 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'hff08, WORD);    // Try to set the bit that was left locked by the RISC
781 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h0000, WORD);   // Verify no bits were set
782 21 rehayes
 
783 11 rehayes
    repeat(20) @(posedge mstr_test_clk);
784
 
785 36 rehayes
    p_ram.dump_ram(0);
786 62 rehayes
 
787 41 rehayes
    read_ram_cmp(16'h0000,16'haa55);
788
    read_ram_cmp(16'h0004,16'h7faa);
789
    read_ram_cmp(16'h0006,16'h6f55);
790
    read_ram_cmp(16'h000a,16'h5f66);
791
    read_ram_cmp(16'h0032,16'h1fcc);
792
    read_ram_cmp(16'h0038,16'h2f99);
793
    read_ram_cmp(16'h0062,16'h1faa);
794
    read_ram_cmp(16'h0068,16'h2fcc);
795
    read_ram_cmp(16'h0022,16'hccxx);
796
    read_ram_cmp(16'h0026,16'hxx99);
797
    read_ram_cmp(16'h0052,16'hxx66);
798
    read_ram_cmp(16'h0058,16'h99xx);
799 62 rehayes
 
800 50 rehayes
    data_xgmctl = 16'hff00;
801 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Disable XGATE
802 50 rehayes
 
803 11 rehayes
  end
804
endtask
805
 
806 36 rehayes
////////////////////////////////////////////////////////////////////////////////
807 2 rehayes
// check register bits - reset, read/write
808
task reg_test_16;
809
  begin
810 65 rehayes
    test_num = test_num + 1;
811
    $display("\nTEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
812 41 rehayes
 
813 65 rehayes
    system_reset;
814 2 rehayes
 
815 65 rehayes
    host.wb_cmp(0, XGATE_XGMCTL,   16'h0000, WORD);      // verify reset
816
    host.wb_cmp(0, XGATE_XGCHID,   16'h0000, WORD);      // verify reset
817
    host.wb_cmp(0, XGATE_XGISPHI,  16'h0000, WORD);      // verify reset
818
    host.wb_cmp(0, XGATE_XGISPLO,  16'h0000, WORD);      // verify reset
819
    host.wb_cmp(0, XGATE_XGVBR,    16'hfe00, WORD);      // verify reset
820
    host.wb_cmp(0, XGATE_XGIF_7,   16'h0000, WORD);      // verify reset
821
    host.wb_cmp(0, XGATE_XGIF_6,   16'h0000, WORD);      // verify reset
822
    host.wb_cmp(0, XGATE_XGIF_5,   16'h0000, WORD);      // verify reset
823
    host.wb_cmp(0, XGATE_XGIF_4,   16'h0000, WORD);      // verify reset
824
    host.wb_cmp(0, XGATE_XGIF_3,   16'h0000, WORD);      // verify reset
825
    host.wb_cmp(0, XGATE_XGIF_2,   16'h0000, WORD);      // verify reset
826
    host.wb_cmp(0, XGATE_XGIF_1,   16'h0000, WORD);      // verify reset
827 73 rehayes
    host.wb_cmp(0, XGATE_XGIF_0,   16'h0000, WORD);      // verify reset
828 65 rehayes
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);      // verify reset
829
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);      // verify reset
830
    host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);      // verify reset
831
    host.wb_cmp(0, XGATE_XGPC,     16'h0000, WORD);      // verify reset
832
    host.wb_cmp(0, XGATE_XGR1,     16'h0000, WORD);      // verify reset
833
    host.wb_cmp(0, XGATE_XGR2,     16'h0000, WORD);      // verify reset
834
    host.wb_cmp(0, XGATE_XGR3,     16'h0000, WORD);      // verify reset
835
    host.wb_cmp(0, XGATE_XGR4,     16'h0000, WORD);      // verify reset
836
    host.wb_cmp(0, XGATE_XGR5,     16'h0000, WORD);      // verify reset
837
    host.wb_cmp(0, XGATE_XGR6,     16'h0000, WORD);      // verify reset
838
    host.wb_cmp(0, XGATE_XGR7,     16'h0000, WORD);      // verify reset
839 62 rehayes
 
840 41 rehayes
/*
841
  parameter XGMCTL_XGDBGM   = 15'h2000;
842
  parameter XGMCTL_XGSSM    = 15'h1000;
843
  parameter XGMCTL_XGBRKIEM = 15'h0400;
844
  parameter XGMCTL_XGSWEIFM = 15'h0200;
845
  parameter XGMCTL_XGIEM    = 15'h0100;
846 2 rehayes
 
847 41 rehayes
  parameter XGMCTL_XGDBG    = 15'h0020;
848 62 rehayes
  parameter XGMCTL_XGSS     = 15'h0010;
849 41 rehayes
  parameter XGMCTL_XGBRKIE  = 15'h0004;
850
  parameter XGMCTL_XGSWEIF  = 15'h0002;
851 62 rehayes
  parameter XGMCTL_XGIE     = 15'h0001;
852 41 rehayes
*/
853 65 rehayes
    // Test bits in the Xgate Control Register (XGMCTL)
854
    data_xgmctl = XGMCTL_XGEM | XGMCTL_XGFRZM | XGMCTL_XGFACTM | XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
855
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
856
    data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
857
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
858 2 rehayes
 
859 65 rehayes
    data_xgmctl = XGMCTL_XGEM;
860
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
861
    data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT;
862
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
863 2 rehayes
 
864 65 rehayes
    data_xgmctl = XGMCTL_XGFRZM | XGMCTL_XGFACTM;
865
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
866
    data_xgmctl = 16'h0000;
867
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
868 41 rehayes
 
869 65 rehayes
    data_xgmctl = 16'hffff;
870
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, H_BYTE);   //
871
    data_xgmctl = 16'h0000;
872
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
873 41 rehayes
 
874 65 rehayes
    data_xgmctl = 16'hffff;
875
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, L_BYTE);   //
876
    data_xgmctl = 16'h0000;
877
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
878 41 rehayes
 
879 65 rehayes
    // Test the Xgate Vector Base Address Register (XGVBR)
880
    host.wb_write(0, XGATE_XGVBR,  16'h5555, WORD);
881
    host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
882 41 rehayes
 
883 65 rehayes
    host.wb_write(0, XGATE_XGVBR,  16'hAAAA, WORD);
884
    host.wb_cmp(0, XGATE_XGVBR,    16'hAAAA, WORD);
885 41 rehayes
 
886 65 rehayes
    host.wb_write(0, XGATE_XGVBR,  16'hFF55, L_BYTE);
887
    host.wb_cmp(0, XGATE_XGVBR,    16'hAA54, WORD);
888 62 rehayes
 
889 65 rehayes
    host.wb_write(0, XGATE_XGVBR,  16'h55AA, H_BYTE);
890
    host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
891 62 rehayes
 
892 65 rehayes
    data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
893
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
894
    data_xgmctl = XGMCTL_XGE;
895
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
896
    host.wb_write(0, XGATE_XGVBR,  16'hFFFF, WORD);
897
    host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
898 41 rehayes
 
899 65 rehayes
    data_xgmctl = XGMCTL_XGEM;
900
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
901 41 rehayes
 
902 65 rehayes
    // Test the Xgate Software Trigger Register (XGSWT)
903
    host.wb_write(0, XGATE_XGSWT,  16'hFFFF, WORD);
904
    host.wb_cmp(0, XGATE_XGSWT,    16'h00FF, WORD);
905
    host.wb_write(0, XGATE_XGSWT,  16'hFF00, WORD);
906
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
907 41 rehayes
 
908 65 rehayes
    host.wb_write(0, XGATE_XGSWT,  16'hFF55, L_BYTE);
909
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
910
    host.wb_write(0, XGATE_XGSWT,  16'hFF55, H_BYTE);
911
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
912 41 rehayes
 
913 65 rehayes
    // Test the Xgate Semaphore Register (XGSEM)
914
    host.wb_write(0, XGATE_XGSEM,  16'hFFFF, WORD);
915
    host.wb_cmp(0, XGATE_XGSEM,    16'h00FF, WORD);
916
    host.wb_write(0, XGATE_XGSEM,  16'hFF00, WORD);
917
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
918 41 rehayes
 
919 65 rehayes
    host.wb_write(0, XGATE_XGSEM,  16'hFFFF, L_BYTE);
920
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
921
    host.wb_write(0, XGATE_XGSEM,  16'hFFFF, H_BYTE);
922
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
923 41 rehayes
 
924 65 rehayes
    // Test the Xgate Condition Code Register (XGCCR)
925
    host.wb_write(0, XGATE_XGCCR,  16'hFFFF, L_BYTE);
926
    host.wb_cmp(0, XGATE_XGCCR,    16'h000F, WORD);
927
    host.wb_write(0, XGATE_XGCCR,  16'hFFF0, WORD);
928
    host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);
929 41 rehayes
 
930 65 rehayes
    // Test the Xgate Program Counter Register (XGPC)
931
    host.wb_write(0, XGATE_XGPC,  16'hFF55, L_BYTE);
932
    host.wb_cmp(0, XGATE_XGPC,    16'h0055, WORD);
933
    host.wb_write(0, XGATE_XGPC,  16'hAAFF, H_BYTE);
934
    host.wb_cmp(0, XGATE_XGPC,    16'hAA55, WORD);
935
    host.wb_write(0, XGATE_XGPC,  16'h9966, WORD);
936
    host.wb_cmp(0, XGATE_XGPC,    16'h9966, WORD);
937 41 rehayes
 
938 65 rehayes
    // Test the Xgate Register #1 (XGR1)
939
    host.wb_write(0, XGATE_XGR1,  16'hFF33, L_BYTE);
940
    host.wb_cmp(0, XGATE_XGR1,    16'h0033, WORD);
941
    host.wb_write(0, XGATE_XGR1,  16'hccFF, H_BYTE);
942
    host.wb_cmp(0, XGATE_XGR1,    16'hcc33, WORD);
943
    host.wb_write(0, XGATE_XGR1,  16'hf11f, WORD);
944
    host.wb_cmp(0, XGATE_XGR1,    16'hf11f, WORD);
945 41 rehayes
 
946 65 rehayes
    // Test the Xgate Register #2 (XGR2)
947
    host.wb_write(0, XGATE_XGR2,  16'hFF11, L_BYTE);
948
    host.wb_cmp(0, XGATE_XGR2,    16'h0011, WORD);
949
    host.wb_write(0, XGATE_XGR2,  16'h22FF, H_BYTE);
950
    host.wb_cmp(0, XGATE_XGR2,    16'h2211, WORD);
951
    host.wb_write(0, XGATE_XGR2,  16'hddee, WORD);
952
    host.wb_cmp(0, XGATE_XGR2,    16'hddee, WORD);
953 41 rehayes
 
954 65 rehayes
    // Test the Xgate Register #3 (XGR3)
955
    host.wb_write(0, XGATE_XGR3,  16'hFF43, L_BYTE);
956
    host.wb_cmp(0, XGATE_XGR3,    16'h0043, WORD);
957
    host.wb_write(0, XGATE_XGR3,  16'h54FF, H_BYTE);
958
    host.wb_cmp(0, XGATE_XGR3,    16'h5443, WORD);
959
    host.wb_write(0, XGATE_XGR3,  16'habbc, WORD);
960
    host.wb_cmp(0, XGATE_XGR3,    16'habbc, WORD);
961 41 rehayes
 
962 65 rehayes
    // Test the Xgate Register #4 (XGR4)
963
    host.wb_write(0, XGATE_XGR4,  16'hFF54, L_BYTE);
964
    host.wb_cmp(0, XGATE_XGR4,    16'h0054, WORD);
965
    host.wb_write(0, XGATE_XGR4,  16'h65FF, H_BYTE);
966
    host.wb_cmp(0, XGATE_XGR4,    16'h6554, WORD);
967
    host.wb_write(0, XGATE_XGR4,  16'h9aab, WORD);
968
    host.wb_cmp(0, XGATE_XGR4,    16'h9aab, WORD);
969 41 rehayes
 
970 65 rehayes
    // Test the Xgate Register #5 (XGR5)
971
    host.wb_write(0, XGATE_XGR5,  16'hFF65, L_BYTE);
972
    host.wb_cmp(0, XGATE_XGR5,    16'h0065, WORD);
973
    host.wb_write(0, XGATE_XGR5,  16'h76FF, H_BYTE);
974
    host.wb_cmp(0, XGATE_XGR5,    16'h7665, WORD);
975
    host.wb_write(0, XGATE_XGR5,  16'h899a, WORD);
976
    host.wb_cmp(0, XGATE_XGR5,    16'h899a, WORD);
977 41 rehayes
 
978 65 rehayes
    // Test the Xgate Register #6 (XGR6)
979
    host.wb_write(0, XGATE_XGR6,  16'hFF76, L_BYTE);
980
    host.wb_cmp(0, XGATE_XGR6,    16'h0076, WORD);
981
    host.wb_write(0, XGATE_XGR6,  16'h87FF, H_BYTE);
982
    host.wb_cmp(0, XGATE_XGR6,    16'h8776, WORD);
983
    host.wb_write(0, XGATE_XGR6,  16'h7889, WORD);
984
    host.wb_cmp(0, XGATE_XGR6,    16'h7889, WORD);
985 41 rehayes
 
986 65 rehayes
    // Test the Xgate Register #7 (XGR7)
987
    host.wb_write(0, XGATE_XGR7,  16'hFF87, L_BYTE);
988
    host.wb_cmp(0, XGATE_XGR7,    16'h0087, WORD);
989
    host.wb_write(0, XGATE_XGR7,  16'h98FF, H_BYTE);
990
    host.wb_cmp(0, XGATE_XGR7,    16'h9887, WORD);
991
    host.wb_write(0, XGATE_XGR7,  16'h6778, WORD);
992
    host.wb_cmp(0, XGATE_XGR7,    16'h6778, WORD);
993 41 rehayes
 
994 65 rehayes
    host.wb_cmp(0, XGATE_XGPC,    16'h9966, WORD);
995
    host.wb_cmp(0, XGATE_XGR1,    16'hf11f, WORD);
996
    host.wb_cmp(0, XGATE_XGR2,    16'hddee, WORD);
997
    host.wb_cmp(0, XGATE_XGR3,    16'habbc, WORD);
998
    host.wb_cmp(0, XGATE_XGR4,    16'h9aab, WORD);
999
    host.wb_cmp(0, XGATE_XGR5,    16'h899a, WORD);
1000
    host.wb_cmp(0, XGATE_XGR6,    16'h7889, WORD);
1001
    host.wb_cmp(0, XGATE_XGR7,    16'h6778, WORD);
1002 41 rehayes
 
1003 2 rehayes
  end
1004
endtask
1005
 
1006 68 rehayes
////////////////////////////////////////////////////////////////////////////////
1007 73 rehayes
// check irq register bits - reset, read/write
1008 68 rehayes
task reg_irq;
1009
  begin
1010
    test_num = test_num + 1;
1011
    $display("\nTEST #%d Starts at vector=%d, reg_irq", test_num, vector);
1012
    $readmemh("../../../bench/verilog/irq_test.v", p_ram.ram_8);
1013 2 rehayes
 
1014 68 rehayes
    system_reset;
1015
 
1016 73 rehayes
    host.wb_cmp(0, IRQ_BYPS_0,   16'hFFFE, WORD);        // verify reset
1017 68 rehayes
    host.wb_cmp(0, IRQ_BYPS_1,   16'hFFFF, WORD);        // verify reset
1018
    host.wb_cmp(0, IRQ_BYPS_2,   16'hFFFF, WORD);        // verify reset
1019
    host.wb_cmp(0, IRQ_BYPS_3,   16'hFFFF, WORD);        // verify reset
1020
    host.wb_cmp(0, IRQ_BYPS_4,   16'hFFFF, WORD);        // verify reset
1021
    host.wb_cmp(0, IRQ_BYPS_5,   16'hFFFF, WORD);        // verify reset
1022
    host.wb_cmp(0, IRQ_BYPS_6,   16'hFFFF, WORD);        // verify reset
1023
    host.wb_cmp(0, IRQ_BYPS_7,   16'hFFFF, WORD);        // verify reset
1024
 
1025
 
1026
    // Test the Xgate IRQ Bypass Registers (IRQ_BYPS)
1027
    host.wb_write(0, IRQ_BYPS_0,  16'hAAAA, WORD);
1028
    host.wb_cmp(0, IRQ_BYPS_0,    16'hAAAA, WORD);
1029
    host.wb_write(0, IRQ_BYPS_0,  16'h5555, WORD);
1030 73 rehayes
    host.wb_cmp(0, IRQ_BYPS_0,    16'h5554, WORD);
1031 68 rehayes
 
1032
    host.wb_write(0, IRQ_BYPS_0,  16'hFF66, L_BYTE);
1033
    host.wb_cmp(0, IRQ_BYPS_0,    16'h5566, WORD);
1034
    host.wb_write(0, IRQ_BYPS_0,  16'h33FF, H_BYTE);
1035
    host.wb_cmp(0, IRQ_BYPS_0,    16'h3366, WORD);
1036
    host.wb_write(0, IRQ_BYPS_0,  16'hFFFF, H_BYTE);
1037
 
1038
    channel_req[17] = 1'b1; //
1039
    repeat(4) @(posedge mstr_test_clk);
1040
    host.wb_cmp(0, CHANNEL_XGIRQ_1,    16'h0002, WORD);
1041
    channel_req[17] = 1'b0; //
1042
    repeat(4) @(posedge mstr_test_clk);
1043
    host.wb_cmp(0, CHANNEL_XGIRQ_1,    16'h0000, WORD);
1044
 
1045
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1046
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
1047
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
1048
    data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
1049
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable XGATE
1050
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1051
    channel_req[3:1] = 3'b111; //
1052
 
1053
    q = 0;
1054
    // The Xgate test program is in an infinate loop for the test bench semaphore register to be changed
1055
    while (q == 0)  // Look for change in test bench semapore register
1056
      begin
1057
        host.wb_read(1, TB_SEMPHORE, q, WORD);
1058
      end
1059
 
1060
    if (q != 1)
1061
      begin
1062
        $display("IRQ test failure, Wrong interrupt being processed! Interrupt=%d, vector=%d", q, vector);
1063
      end
1064
 
1065
    channel_req[1] = 1'b0; //
1066
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1067
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1068
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1069
 
1070
//    host.wb_cmp(0, CHANNEL_XGIRQ_0, 16'h0002, WORD);  // Verify Xgate output interrupt flag set
1071
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0002, WORD);  // Verify Xgate interrupt status bit set
1072
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);  // Clear Interrupt Flag from Xgate
1073
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0000, WORD);  // Verify flag cleared
1074
 
1075
    q = 0;
1076
    // The Xgate test program is in an infinate loop for the test bench semaphore register to be changed
1077
    while (q == 0)  // Look for change in test bench semapore register
1078
      begin
1079
        host.wb_read(1, TB_SEMPHORE, q, WORD);
1080
      end
1081
 
1082
    if (q != 2)
1083
      begin
1084
        $display("IRQ test failure, Wrong interrupt being processed! Interrupt=%d, vector=%d", q, vector);
1085
      end
1086
 
1087
    channel_req[2] = 1'b0; //
1088
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1089
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1090
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1091
 
1092
//    host.wb_cmp(0, CHANNEL_XGIRQ_0, 16'h0002, WORD);  // Verify Xgate output interrupt flag set
1093
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0002, WORD);  // Verify Xgate interrupt status bit set
1094
    host.wb_write(1, XGATE_XGIF_0, 16'h0004, WORD);  // Clear Interrupt Flag from Xgate
1095
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0000, WORD);  // Verify flag cleared
1096
 
1097
    q = 0;
1098
    // The Xgate test program is in an infinate loop for the test bench semaphore register to be changed
1099
    while (q == 0)  // Look for change in test bench semapore register
1100
      begin
1101
        host.wb_read(1, TB_SEMPHORE, q, WORD);
1102
      end
1103
 
1104
    if (q != 3)
1105
      begin
1106
        $display("IRQ test failure, Wrong interrupt being processed! Interrupt=%d, vector=%d", q, vector);
1107
      end
1108
 
1109
    channel_req[3] = 1'b0; //
1110
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1111
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1112
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1113
 
1114
//    host.wb_cmp(0, CHANNEL_XGIRQ_0, 16'h0002, WORD);  // Verify Xgate output interrupt flag set
1115
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0002, WORD);  // Verify Xgate interrupt status bit set
1116
    host.wb_write(1, XGATE_XGIF_0, 16'h0008, WORD);  // Clear Interrupt Flag from Xgate
1117
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0000, WORD);  // Verify flag cleared
1118
 
1119
  end
1120
endtask
1121
 
1122
 
1123 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1124
// check RAM Read/Write from host
1125
task host_ram;
1126
  begin
1127
    test_num = test_num + 1;
1128 65 rehayes
    $display("\nTEST #%d Starts at vector=%d, host_ram", test_num, vector);
1129 36 rehayes
 
1130
    host.wb_write(1, SYS_RAM_BASE, 16'h5555, WORD);
1131
    host.wb_cmp(  0, SYS_RAM_BASE, 16'h5555, WORD);
1132
 
1133
    repeat(5) @(posedge mstr_test_clk);
1134
    p_ram.dump_ram(0);
1135
 
1136
  end
1137
endtask
1138
 
1139
////////////////////////////////////////////////////////////////////////////////
1140 11 rehayes
// Poll for XGATE Interrupt set
1141
task wait_irq_set;
1142
  input [ 6:0] chan_val;
1143
  begin
1144
    while(!xgif[chan_val])
1145
      @(posedge mstr_test_clk); // poll it until it is set
1146
    $display("XGATE Interrupt Request #%d set detected at vector =%d", chan_val, vector);
1147
  end
1148
endtask
1149 2 rehayes
 
1150 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1151 11 rehayes
// Poll for debug bit set
1152
task wait_debug_set;
1153
  begin
1154 36 rehayes
    host.wb_read(1, XGATE_XGMCTL, q, WORD);
1155 11 rehayes
    while(~|(q & XGMCTL_XGDBG))
1156 36 rehayes
      host.wb_read(1, XGATE_XGMCTL, q, WORD); // poll it until it is set
1157 11 rehayes
    $display("DEBUG Flag set detected at vector =%d", vector);
1158
  end
1159
endtask
1160 2 rehayes
 
1161 11 rehayes
 
1162 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1163 2 rehayes
task system_reset;  // reset system
1164
  begin
1165
      repeat(1) @(posedge mstr_test_clk);
1166
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
1167 62 rehayes
      #2;                 // move the async reset away from the clock edge
1168
      rstn = 1'b0;        // assert async reset
1169
      #5;                 // Keep the async reset pulse with less than a clock cycle
1170
      rstn = 1'b1;        // negate async reset
1171 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1172
      sync_reset = 1'b0;
1173
 
1174
      $display("\nstatus: %t System Reset Task Done", $time);
1175
      test_num = test_num + 1;
1176
 
1177
      repeat(2) @(posedge mstr_test_clk);
1178
   end
1179
endtask
1180
 
1181
 
1182 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1183 2 rehayes
task activate_channel;
1184
  input [ 6:0] chan_val;
1185
  begin
1186 21 rehayes
    $display("Activating Channel %d", chan_val);
1187 2 rehayes
 
1188 21 rehayes
    channel_req[chan_val] = 1'b1; //
1189
    repeat(1) @(posedge mstr_test_clk);
1190 2 rehayes
  end
1191
endtask
1192
 
1193
 
1194 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1195 2 rehayes
task clear_channel;
1196
  input [ 6:0] chan_val;
1197
  begin
1198 21 rehayes
    $display("Clearing Channel interrupt input #%d", chan_val);
1199 2 rehayes
 
1200 21 rehayes
    channel_req[chan_val] = 1'b0; //
1201
    repeat(1) @(posedge mstr_test_clk);
1202
  end
1203 2 rehayes
endtask
1204
 
1205
 
1206 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1207 2 rehayes
task clear_irq_flag;
1208
  input [ 6:0] chan_val;
1209
  begin
1210
      $display("Clearing Channel interrupt flag #%d", chan_val);
1211
      if (0 < chan_val < 16)
1212 62 rehayes
        host.wb_write(1, XGATE_XGIF_0, 16'hffff, WORD);
1213 2 rehayes
      if (15 < chan_val < 32)
1214 62 rehayes
        host.wb_write(1, XGATE_XGIF_1, 16'hffff, WORD);
1215 2 rehayes
      if (31 < chan_val < 48)
1216 62 rehayes
        host.wb_write(1, XGATE_XGIF_2, 16'hffff, WORD);
1217 2 rehayes
      if (47 < chan_val < 64)
1218 62 rehayes
        host.wb_write(1, XGATE_XGIF_3, 16'hffff, WORD);
1219 2 rehayes
      if (63 < chan_val < 80)
1220 62 rehayes
        host.wb_write(1, XGATE_XGIF_4, 16'hffff, WORD);
1221 2 rehayes
      if (79 < chan_val < 96)
1222 62 rehayes
        host.wb_write(1, XGATE_XGIF_5, 16'hffff, WORD);
1223 2 rehayes
      if (95 < chan_val < 112)
1224 62 rehayes
        host.wb_write(1, XGATE_XGIF_6, 16'hffff, WORD);
1225 2 rehayes
      if (111 < chan_val < 128)
1226 62 rehayes
        host.wb_write(1, XGATE_XGIF_7, 16'hffff, WORD);
1227 2 rehayes
 
1228 21 rehayes
      channel_req[chan_val] = 1'b0; //
1229 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1230
   end
1231
endtask
1232
 
1233
 
1234 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1235 2 rehayes
task activate_thread_sw;
1236
  input [ 6:0] chan_val;
1237
  begin
1238 50 rehayes
      $display("Activating Software Thread - Channel #%d", chan_val);
1239 2 rehayes
 
1240 11 rehayes
      data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
1241 36 rehayes
      host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable XGATE
1242 2 rehayes
 
1243 21 rehayes
      channel_req[chan_val] = 1'b1; //
1244 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1245
   end
1246
endtask
1247
 
1248 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1249 41 rehayes
task read_ram_cmp;
1250
  input [15:0] address;
1251
  input [15:0] value;
1252 62 rehayes
  reg   [15:0] q;
1253 41 rehayes
  begin
1254
 
1255
      // BIGENDIAN
1256
      q = {p_ram.ram_8[address], p_ram.ram_8[address+1]};
1257
      // "X" compares don't work, "X" in value or q always match
1258
      if (value != q)
1259
        begin
1260 62 rehayes
          error_count = error_count + 1;
1261
          $display("RAM Data compare error at address %h. Received %h, expected %h at time %t", address, q, value, $time);
1262 41 rehayes
        end
1263
   end
1264
endtask
1265
 
1266
////////////////////////////////////////////////////////////////////////////////
1267 5 rehayes
task wrap_up;
1268
  begin
1269 21 rehayes
    test_num = test_num + 1;
1270
    repeat(10) @(posedge mstr_test_clk);
1271 5 rehayes
    $display("\nSimulation Finished!! - vector =%d", vector);
1272
    if (error_count == 0)
1273
      $display("Simulation Passed");
1274
    else
1275 21 rehayes
      $display("Simulation Failed  --- Errors =%d", error_count);
1276 5 rehayes
 
1277
    $finish;
1278
  end
1279
endtask
1280
 
1281 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1282 2 rehayes
function [15:0] four_2_16;
1283
  input [3:0] vector;
1284
  begin
1285
    case (vector)
1286
      4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
1287
      4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
1288
      4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
1289
      4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
1290
      4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
1291
      4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
1292
      4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
1293
      4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
1294
      4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
1295
      4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
1296
      4'ha : four_2_16 = 16'b0000_0100_0000_0000;
1297
      4'hb : four_2_16 = 16'b0000_1000_0000_0000;
1298
      4'hc : four_2_16 = 16'b0001_0000_0000_0000;
1299
      4'hd : four_2_16 = 16'b0010_0000_0000_0000;
1300
      4'he : four_2_16 = 16'b0100_0000_0000_0000;
1301
      4'hf : four_2_16 = 16'b1000_0000_0000_0000;
1302
    endcase
1303
  end
1304
endfunction
1305
 
1306
endmodule  // tst_bench_top
1307
 
1308 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1309
////////////////////////////////////////////////////////////////////////////////
1310
////////////////////////////////////////////////////////////////////////////////
1311 62 rehayes
module bus_arbitration  #(parameter dwidth = 16,
1312
                          parameter awidth = 24,
1313 54 rehayes
                          parameter ram_base = 0,
1314
                          parameter ram_size = 16'hffff,
1315
                          parameter slv1_base = 0,
1316
                          parameter slv1_size = 1,
1317
                          parameter slv2_base = 0,
1318 65 rehayes
                          parameter slv2_size = 1,
1319
                          parameter ram_wait_states = 0) // Number between 0 and 15
1320 36 rehayes
  (
1321
  // System bus I/O
1322 62 rehayes
  output reg                 sys_cyc,
1323
  output reg                 sys_stb,
1324
  output reg                 sys_we,
1325 54 rehayes
  output reg [dwidth/8 -1:0] sys_sel,
1326
  output reg [awidth   -1:0] sys_adr,
1327
  output reg [dwidth   -1:0] sys_dout,
1328
  output     [dwidth   -1:0] sys_din,
1329 62 rehayes
 
1330 36 rehayes
  // Host bus I/O
1331 62 rehayes
  output                     host_ack,
1332 36 rehayes
  output     [dwidth   -1:0] host_dout,
1333 62 rehayes
  input                      host_cyc,
1334
  input                      host_stb,
1335
  input                      host_we,
1336
  input      [dwidth/8 -1:0] host_sel,
1337
  input      [awidth   -1:0] host_adr,
1338
  input      [dwidth   -1:0] host_din,
1339
 
1340 36 rehayes
  // Alternate Bus Master #1 Bus I/O
1341 62 rehayes
  output                     alt1_ack,
1342 36 rehayes
  output     [dwidth   -1:0] alt1_dout,
1343 62 rehayes
  input                      alt1_cyc,
1344
  input                      alt1_stb,
1345
  input                      alt1_we,
1346
  input      [dwidth/8 -1:0] alt1_sel,
1347
  input      [awidth   -1:0] alt1_adr,
1348
  input      [dwidth   -1:0] alt1_din,
1349
 
1350 54 rehayes
  // System RAM memory signals
1351 62 rehayes
  output                     ram_sel,
1352
  input      [dwidth   -1:0] ram_dout,
1353 54 rehayes
 
1354 36 rehayes
  // Slave #1 Bus I/O
1355 62 rehayes
  output                     slv1_stb,
1356
  input                      slv1_ack,
1357
  input      [dwidth   -1:0] slv1_din,
1358
 
1359 36 rehayes
  // Slave #2 Bus I/O
1360 62 rehayes
  output                     slv2_stb,
1361
  input                      slv2_ack,
1362
  input      [dwidth   -1:0] slv2_din,
1363
 
1364 36 rehayes
  // Miscellaneous
1365 62 rehayes
  input                      host_clk,
1366
  input                      risc_clk,
1367
  input                      rst,  // No Connect
1368
  input                      err,  // No Connect
1369
  input                      rty   // No Connect
1370 36 rehayes
  );
1371 62 rehayes
 
1372 60 rehayes
  // States for bus arbitration
1373 54 rehayes
  parameter [1:0] BUS_IDLE = 2'b00,
1374 62 rehayes
                  HOST_OWNS = 2'b10,
1375
                  RISC_OWNS = 2'b11;
1376
 
1377
  parameter max_bus_hold = 5;    // Max number of cycles any bus master can hold the system bus
1378 36 rehayes
  //////////////////////////////////////////////////////////////////////////////
1379
  //
1380
  // Local Wires and Registers
1381
  //
1382 62 rehayes
  wire       ram_ack;        //
1383
  wire       any_ack;        //
1384
  reg        host_wait;      // Host bus in wait state, Hold the bus till the transaction complets
1385 36 rehayes
  reg  [3:0] host_cycle_cnt; // Used to count the cycle the host and break the lock if the risc needs access
1386 62 rehayes
 
1387
  wire       risc_lock;      // RISC has the slave bus
1388
  reg        risc_wait;      // RISC bus in wait state, Hold the bus till the transaction complets
1389 36 rehayes
  reg  [3:0] risc_cycle_cnt; // Used to count the cycle the risc and break the lock if the host needs access
1390 62 rehayes
 
1391 54 rehayes
  reg  [1:0] owner_state;
1392
  reg  [1:0] owner_ns;
1393 36 rehayes
 
1394 62 rehayes
  wire       host_timeout;
1395
  wire       risc_timeout;
1396
 
1397
  wire       ram_ack_dly;    // Delayed bus ack to simulate bus wait states
1398 60 rehayes
  reg  [3:0] ack_dly_cnt;    // Counter to delay bus ack to master modules
1399 54 rehayes
 
1400
 
1401
  //
1402 36 rehayes
  always @(posedge host_clk or negedge rst)
1403
    if (!rst)
1404 54 rehayes
      owner_state <= BUS_IDLE;
1405 36 rehayes
    else
1406 54 rehayes
      owner_state <= owner_ns;
1407 62 rehayes
 
1408 54 rehayes
  //
1409
  always @*
1410
    case (owner_state)
1411
      BUS_IDLE :
1412
        begin
1413
          if (host_cyc)
1414
            owner_ns = HOST_OWNS;
1415
          else if (alt1_cyc)
1416
            owner_ns = RISC_OWNS;
1417
        end
1418
      HOST_OWNS :
1419
        begin
1420
          if (!host_cyc && !alt1_cyc)
1421
            owner_ns = BUS_IDLE;
1422
          else if (alt1_cyc && (!host_cyc || host_timeout))
1423
            owner_ns = RISC_OWNS;
1424
        end
1425
      RISC_OWNS :
1426
        begin
1427
          if (!host_cyc && !alt1_cyc)
1428
            owner_ns = BUS_IDLE;
1429
          else if (host_cyc && (!alt1_cyc || risc_timeout))
1430
            owner_ns = HOST_OWNS;
1431
        end
1432
      default : owner_ns = BUS_IDLE;
1433
    endcase
1434 36 rehayes
 
1435 62 rehayes
 
1436 60 rehayes
  assign host_timeout = (owner_state == HOST_OWNS) && (host_cycle_cnt > max_bus_hold) && any_ack;
1437
  assign risc_timeout = (owner_state == RISC_OWNS) && (risc_cycle_cnt > max_bus_hold) && any_ack;
1438 54 rehayes
 
1439
  // Start counting cycles that the host has the bus, if the risc is also requesting the bus
1440 36 rehayes
  always @(posedge host_clk or negedge rst)
1441
    if (!rst)
1442
      host_cycle_cnt <= 0;
1443 54 rehayes
    else if ((owner_state != HOST_OWNS) || !alt1_cyc)
1444
      host_cycle_cnt <= 0;
1445 62 rehayes
    else if (&host_cycle_cnt && !host_timeout)  // Don't allow rollover
1446 54 rehayes
      host_cycle_cnt <= host_cycle_cnt;
1447
    else if ((owner_state == HOST_OWNS) && alt1_cyc)
1448
      host_cycle_cnt <= host_cycle_cnt + 1'b1;
1449 36 rehayes
 
1450 54 rehayes
  // Start counting cycles that the risc has the bus, if the host is also requesting the bus
1451 36 rehayes
  always @(posedge host_clk or negedge rst)
1452
    if (!rst)
1453
      risc_cycle_cnt <= 0;
1454 54 rehayes
    else if ((owner_state != RISC_OWNS) || !host_cyc)
1455
      risc_cycle_cnt <= 0;
1456 62 rehayes
    else if (&risc_cycle_cnt && !risc_timeout)  // Don't allow rollover
1457 54 rehayes
      risc_cycle_cnt <= risc_cycle_cnt;
1458
    else if ((owner_state == RISC_OWNS) && host_cyc)
1459
      risc_cycle_cnt <= risc_cycle_cnt + 1'b1;
1460 36 rehayes
 
1461 62 rehayes
  // Aribartration Logic for System Bus access
1462 54 rehayes
  assign any_ack  = slv1_ack || slv2_ack || ram_ack;
1463
  assign host_ack = (owner_state == HOST_OWNS) && any_ack && host_cyc;
1464
  assign alt1_ack = (owner_state == RISC_OWNS) && any_ack && alt1_cyc;
1465 36 rehayes
 
1466 54 rehayes
 
1467
  // Address decoding for different Slave module instances
1468
  assign slv1_stb = sys_stb && (sys_adr >= slv1_base) && (sys_adr < (slv1_base + slv1_size));
1469
  assign slv2_stb = sys_stb && (sys_adr >= slv2_base) && (sys_adr < (slv2_base + slv2_size));
1470 62 rehayes
 
1471 36 rehayes
  // Address decoding for Testbench access to RAM
1472 54 rehayes
  assign ram_sel = sys_cyc && sys_stb && !(slv1_stb || slv2_stb) &&
1473 62 rehayes
                   (sys_adr >= ram_base) &&
1474 54 rehayes
                   (sys_adr < (ram_base + ram_size));
1475 62 rehayes
 
1476 60 rehayes
  // Throw in some wait states from the memory
1477
  always @(posedge host_clk)
1478
    if ((ack_dly_cnt == ram_wait_states) || !ram_sel)
1479
      ack_dly_cnt <= 0;
1480
    else if (ram_sel)
1481
      ack_dly_cnt <= ack_dly_cnt + 1'b1;
1482 36 rehayes
 
1483 60 rehayes
  assign ram_ack_dly = (ack_dly_cnt == ram_wait_states);
1484
  assign ram_ack = ram_sel && ram_ack_dly;
1485 36 rehayes
 
1486 60 rehayes
 
1487 54 rehayes
  // Create the System Read Data Bus from the Slave output data buses
1488 68 rehayes
  assign sys_din = ({dwidth{1'b1}} & slv1_din) |
1489 62 rehayes
                   ({dwidth{slv2_stb}} & slv2_din) |
1490
                   ({dwidth{ram_sel}}  & ram_dout);
1491 36 rehayes
 
1492 54 rehayes
  // Mux for System Bus access
1493
  always @*
1494
    case (owner_state)
1495
      BUS_IDLE :
1496
        begin
1497 62 rehayes
          sys_cyc   = 0;
1498
          sys_stb   = 0;
1499
          sys_we    = 0;
1500
          sys_sel   = 0;
1501
          sys_adr   = 0;
1502
          sys_dout  = 0;
1503 54 rehayes
        end
1504
      HOST_OWNS :
1505
        begin
1506 62 rehayes
          sys_cyc   = host_cyc;
1507
          sys_stb   = host_stb;
1508
          sys_we    = host_we;
1509
          sys_sel   = host_sel;
1510
          sys_adr   = host_adr;
1511
          sys_dout  = host_din;
1512 54 rehayes
        end
1513
      RISC_OWNS :
1514
        begin
1515 62 rehayes
          sys_cyc   = alt1_cyc;
1516
          sys_stb   = alt1_stb;
1517
          sys_we    = alt1_we;
1518
          sys_sel   = alt1_sel;
1519
          sys_adr   = alt1_adr;
1520
          sys_dout  = alt1_din;
1521 54 rehayes
        end
1522
      default :
1523
        begin
1524 62 rehayes
          sys_cyc   = 0;
1525
          sys_stb   = 0;
1526
          sys_we    = 0;
1527
          sys_sel   = 0;
1528
          sys_adr   = 0;
1529
          sys_dout  = 0;
1530 54 rehayes
        end
1531
    endcase
1532 36 rehayes
 
1533 54 rehayes
endmodule   // bus_arbitration
1534 36 rehayes
 
1535 54 rehayes
////////////////////////////////////////////////////////////////////////////////
1536
////////////////////////////////////////////////////////////////////////////////
1537
////////////////////////////////////////////////////////////////////////////////
1538
module tb_slave #(parameter SINGLE_CYCLE = 1'b0,  // No bus wait state added
1539 68 rehayes
                  parameter MAX_CHANNEL = 127,    // Max XGATE Interrupt Channel Number
1540 62 rehayes
                  parameter DWIDTH = 16)          // Data bus width
1541 54 rehayes
  (
1542
  // Wishbone Signals
1543 62 rehayes
  output [DWIDTH-1:0] wb_dat_o,      // databus output
1544
  output              wb_ack_o,     // bus cycle acknowledge output
1545
  input               wb_clk_i,     // master clock input
1546
  input               wb_rst_i,     // synchronous active high reset
1547
  input               arst_i,       // asynchronous reset
1548 68 rehayes
  input         [3:0] wb_adr_i,      // lower address bits
1549 62 rehayes
  input  [DWIDTH-1:0] wb_dat_i,      // databus input
1550
  input               wb_we_i,      // write enable input
1551
  input               wb_stb_i,     // stobe/core select signal
1552
  input               wb_cyc_i,     // valid bus cycle input
1553
  input         [1:0] wb_sel_i,      // Select byte in word bus transaction
1554
  // Slave unique IO Signals
1555
  output reg          error_pulse,  // Error detected output pulse
1556
  output reg          ack_pulse,    // Thread ack output pulse
1557 65 rehayes
  output              brk_pt,       // Break point
1558 68 rehayes
  input        [15:0] x_address,    // XGATE WISHBONE Master bus address
1559 73 rehayes
  input [MAX_CHANNEL:1] xgif,       // XGATE Interrupt Flag to Host
1560 62 rehayes
  input        [19:0] vector
1561 54 rehayes
  );
1562 62 rehayes
 
1563
  wire                  async_rst_b;   // Asyncronous reset
1564
  wire                  sync_reset;    // Syncronous reset
1565
 
1566 54 rehayes
  // Wishbone Bus interface
1567
  // registers
1568 68 rehayes
  reg               bus_wait_state;  // Holdoff wb_ack_o for one clock to add wait state
1569
  reg  [DWIDTH-1:0] rd_data_mux;     // Pseudo Register, WISHBONE Read Data Mux
1570
  reg  [DWIDTH-1:0] rd_data_reg;     // Latch for WISHBONE Read Data
1571 36 rehayes
 
1572 68 rehayes
  reg  [DWIDTH-1:0] check_point_reg;
1573
  reg  [DWIDTH-1:0] channel_ack_reg;
1574
  reg  [DWIDTH-1:0] channel_err_reg;
1575 36 rehayes
 
1576 68 rehayes
  reg  [DWIDTH-1:0] brkpt_addr_reg;  // Break Point Address reg
1577
  reg  [DWIDTH-1:0] brkpt_cntl_reg;  // Break Point Control reg
1578 65 rehayes
 
1579 68 rehayes
  reg  [DWIDTH-1:0] tb_semaphr_reg;  // Test bench semaphore reg
1580
 
1581 54 rehayes
  event check_point_wrt;
1582
  event channel_ack_wrt;
1583
  event channel_err_wrt;
1584 36 rehayes
 
1585 54 rehayes
  // Wires
1586 62 rehayes
  wire   module_sel;      // This module is selected for bus transaction
1587
  wire   wb_wacc;         // WISHBONE Write Strobe
1588
  wire   wb_racc;         // WISHBONE Read Access (Clock gating signal)
1589 36 rehayes
 
1590 54 rehayes
  //
1591
  // module body
1592
  //
1593 36 rehayes
 
1594 54 rehayes
  // generate internal resets
1595
 
1596
 
1597
  // generate wishbone signals
1598
  assign module_sel = wb_cyc_i && wb_stb_i;
1599
  assign wb_wacc    = module_sel && wb_we_i && (wb_ack_o || SINGLE_CYCLE);
1600
  assign wb_racc    = module_sel && !wb_we_i;
1601
  assign wb_ack_o   = SINGLE_CYCLE ? module_sel : bus_wait_state;
1602
  assign wb_dat_o   = SINGLE_CYCLE ? rd_data_mux : rd_data_reg;
1603
 
1604
  // generate acknowledge output signal, By using register all accesses takes two cycles.
1605
  //  Accesses in back to back clock cycles are not possable.
1606
  always @(posedge wb_clk_i or negedge arst_i)
1607
    if (!arst_i)
1608 62 rehayes
      bus_wait_state <=  1'b0;
1609 54 rehayes
    else if (wb_rst_i)
1610 62 rehayes
      bus_wait_state <=  1'b0;
1611 54 rehayes
    else
1612 62 rehayes
      bus_wait_state <=  module_sel && !bus_wait_state;
1613 54 rehayes
 
1614
  // assign data read bus -- DAT_O
1615
  always @(posedge wb_clk_i)
1616 62 rehayes
    if ( wb_racc )                     // Clock gate for power saving
1617 54 rehayes
      rd_data_reg <= rd_data_mux;
1618
 
1619
  // WISHBONE Read Data Mux
1620
  always @*
1621
    case (wb_adr_i) // synopsys parallel_case
1622 68 rehayes
      4'b0000: rd_data_mux = check_point_reg;
1623
      4'b0001: rd_data_mux = channel_ack_reg;
1624
      4'b0010: rd_data_mux = channel_err_reg;
1625
      4'b0011: rd_data_mux = brkpt_cntl_reg;
1626
      4'b0100: rd_data_mux = brkpt_addr_reg;
1627
      4'b0101: rd_data_mux = tb_semaphr_reg;
1628 73 rehayes
      4'b1000: rd_data_mux = {xgif[15: 1], 1'b0};
1629 68 rehayes
      4'b1001: rd_data_mux = xgif[31:16];
1630
      4'b1010: rd_data_mux = xgif[47:32];
1631
      4'b1011: rd_data_mux = xgif[63:48];
1632
      4'b1100: rd_data_mux = xgif[79:64];
1633
      4'b1101: rd_data_mux = xgif[95:80];
1634
      4'b1110: rd_data_mux = xgif[111:96];
1635
      4'b1111: rd_data_mux = xgif[127:112];
1636
      default: rd_data_mux = {DWIDTH{1'b0}};
1637 54 rehayes
    endcase
1638
 
1639
  // generate wishbone write register strobes
1640
  always @(posedge wb_clk_i or negedge arst_i)
1641
    begin
1642
      if (!arst_i)
1643 62 rehayes
        begin
1644
          check_point_reg <= 0;
1645
          channel_ack_reg <= 0;
1646
          channel_err_reg <= 0;
1647
          ack_pulse       <= 0;
1648
          error_pulse     <= 0;
1649 68 rehayes
          brkpt_cntl_reg  <= 0;
1650
          brkpt_addr_reg  <= 0;
1651
          tb_semaphr_reg  <= 0;
1652 62 rehayes
        end
1653 54 rehayes
      else if (wb_wacc)
1654
        case (wb_adr_i) // synopsys parallel_case
1655
           3'b000 :
1656
             begin
1657 62 rehayes
               check_point_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : check_point_reg[ 7:0];
1658
               check_point_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : check_point_reg[15:8];
1659
               -> check_point_wrt;
1660 54 rehayes
             end
1661
           3'b001 :
1662
             begin
1663 62 rehayes
               channel_ack_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : channel_ack_reg[ 7:0];
1664
               channel_ack_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : channel_ack_reg[15:8];
1665 54 rehayes
               ack_pulse <= 1;
1666 62 rehayes
               -> channel_ack_wrt;
1667 54 rehayes
             end
1668
           3'b010 :
1669
             begin
1670 62 rehayes
               channel_err_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : channel_err_reg[ 7:0];
1671
               channel_err_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : channel_err_reg[15:8];
1672 54 rehayes
               error_pulse <= 1'b1;
1673 62 rehayes
               -> channel_err_wrt;
1674 54 rehayes
             end
1675
           3'b011 :
1676
             begin
1677 65 rehayes
               brkpt_cntl_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : brkpt_cntl_reg[ 7:0];
1678
               brkpt_cntl_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : brkpt_cntl_reg[15:8];
1679 54 rehayes
             end
1680 65 rehayes
           3'b100 :
1681
             begin
1682
               brkpt_addr_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : brkpt_addr_reg[ 7:0];
1683
               brkpt_addr_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : brkpt_addr_reg[15:8];
1684
             end
1685 68 rehayes
           3'b101 :
1686
             begin
1687
               tb_semaphr_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : tb_semaphr_reg[ 7:0];
1688
               tb_semaphr_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : tb_semaphr_reg[15:8];
1689
             end
1690 54 rehayes
           default: ;
1691
        endcase
1692
      else
1693
        begin
1694
          ack_pulse   <= 0;
1695
          error_pulse <= 1'b0;
1696 62 rehayes
        end
1697 54 rehayes
    end
1698
 
1699
  always @check_point_wrt
1700
    begin
1701
      #1;
1702
      $display("\nSoftware Checkpoint #%h -- at vector=%d\n", check_point_reg, vector);
1703
    end
1704
 
1705
  always @channel_err_wrt
1706
    begin
1707
      #1;
1708 62 rehayes
      $display("\n ------ !!!!! Software Checkpoint Error #%d -- at vector=%d\n  -------", channel_err_reg, vector);
1709 54 rehayes
    end
1710
 
1711
 
1712
endmodule // tb_slave
1713
 

powered by: WebSVN 2.1.0

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