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

Subversion Repositories xgate

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

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

powered by: WebSVN 2.1.0

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